cd C:UsersadmirDesktop分析师精度排名 capture erase merge_list.dta xls2dta: import excel merge_list.xlsx,first case(lower) //第一列即为列名 use merge_list.dta,clear //查看变量类型,防止变量类型导致不能变化 foreach var of varlist _all{ local x : type `var' local x2=substr("`x'",1,3) //从第一个字符开始提取长度为3的内容 if "`x2'" == "str"{ noisily :dis "文件夹`file'中的`var'是字符型变量,需要修改成数值型变量" } } sort assrank gen g_assrank = group(5) //工资等分为五组 br assrank g_assrank tab g_assrank //样本数基本信息 label define g_assrank 1 "High" 5 "Low" label value g_assrank g_assrank //将变量与标签内容关联起来 tabstat acu ope_revenue net_margin, /// stat(mean) by(g_assrank) format(%4.2f) //分组回归 local x "assrank" reg acu `x' if g_assrank==1, robust est store Low reg acu `x' if g_assrank==3, robust est store Mid reg acu `x' if g_assrank==5, robust est store High reg acu `x' , robust est store Full local m "Low Mid High Full" esttab `m', mtitle(`m') nogap s(r2 r2_a N) b(%6.3f) /// star(* 0.1 ** 0.05 *** 0.01) logout, save(tab_stat1) excel replace fix(15) //统计结果输出为excel格式 export excel using "FM_SUMMARIZE.xlsx", firstrow(variable) sheet(AAR_file) //输出这张表