Stata:回归结果导出-parmest

发布时间:2021-10-22 阅读 16164

Stata连享会   主页 || 视频 || 推文 || 知乎 || Bilibili 站

温馨提示: 定期 清理浏览器缓存,可以获得最佳浏览体验。

New! lianxh 命令发布了:
随时搜索推文、Stata 资源。安装:
. ssc install lianxh
详情参见帮助文件 (有惊喜):
. help lianxh
连享会新命令:cnssc, ihelp, rdbalance, gitee, installpkg

课程详情 https://gitee.com/lianxh/Course

课程主页 https://gitee.com/lianxh/Course

⛳ Stata 系列推文:

PDF下载 - 推文合集

作者:卜文超 (南开大学)
邮箱buwenchao420@163.com


目录


1. 引言

在使用 Stata 进行计量分析时,我们经常会通过 eststoesttab 等命令将回归结果以表格形式导出。但在一些特定情形下,我们需要提取回归的系数、标准误、置信区间等信息。此时,采用外部命令 parmest 将会更加方便。

2. parmest 命令

*命令安装
ssc install parmest, replace
*命令语法
parmest , [ parmest_outdest_opts parmest_ci_opts parmest_varadd_opts parmest_varmod_opts ]
  • parmest_outdest_opts:系数导出形式;
  • parmest_ci_opts:系数对应的置信区间;
  • parmest_varadd_opts:变量添加选项;
  • parmest_varmod_opts:系数估计过程的其他统计量;
  • 该命令还可以添加其他 options,如 listframesavingnorestorefastflist 等。

3. Stata 实操

3.1 基本用法

. sysuse auto, clear
. regress price mpg weight foreign displacement headroom, robust
. parmest, label format(p %8.2f) stars(0.1 0.05 0.01) ///
>   list(parm label estimate min95 max95 p stars, clean noobs)

   parm            label    estimate       min95       max95     p  stars  
    mpg     Mileage (mpg)   11.138993  -142.85626   165.13424  0.89         
 weight     Weight (lbs.)   2.6353046   .98851431   4.2820949  0.00  ***    
foreign        Car origin   3939.2529   2598.6615   5279.8442  0.00  ***    
dis~mnt Dis~mnt (cu. in.)    11.65283   1.0224941   22.283165  0.03  **     
headr~m    Headroom (in.)  -710.25453  -1276.5386  -143.97049  0.01  **     
  _cons          Constant  -3373.4056  -10275.086   3528.2744  0.33      

. /*
> format(p %8.2f) 指定 p 值显示格式为 8 个字符长度, 保留小数点后 2 位;
> stars(0.1 0.05 0.01) 指定系数通过 10% 水平的显著性检验时显示 1 颗星, 
> 系数通过 5% 水平的显著性检验时显示 2 颗星, 系数通过 1% 水平的显著性
> 检验时显示 3 颗星;
> list(parm label estimate min95 max95 p stars, clean noobs) 指定结果
> 显示估计系数对应的变量名称、变量标签、系数值、下 95% 置信区间、上 
> 95%置信区间、p值、显著性检验结果.
> */
  
. parmest, saving("ols_estimate.dta", replace) format(parm %20s ///
>   estimate %8.3f std %8.3f t %8.3f min95 %8.3f max95 %8.3f p %8.2f)

. /*
> saving("ols_estimate.dta", replace) 指定以 "ols_estimate.dta" 为文件名
> 保存估计结果, 其中 replace 选项表示替换原有同名数据文件;
> format() 指定显示规则, 如 "estimate %8.3f" 表示以 8 个字符长度保存系数的
> 估计值, 并保留3位小数.
> */

. use ols_estimate, clear
. list, clean noobs                         

        parm  estimate    stderr  dof       t     p     min95     max95  
         mpg    11.139    77.172   68   0.144  0.89  -142.856   165.134  
      weight     2.635     0.825   68   3.193  0.00     0.989     4.282  
     foreign  3939.253   671.818   68   5.864  0.00  2598.662  5279.844  
displacement    11.653     5.327   68   2.187  0.03     1.022    22.283  
    headroom  -710.255   283.785   68  -2.503  0.01  -1.3e+03  -143.970  
       _cons  -3.4e+03  3458.676   68  -0.975  0.33  -1.0e+04  3528.274  

. /*
> parm 表示变量名称, estimate 表示系数的估计值, stderr 表示标准误, 
> dof 表示自由度, t 表示 t 值; p 表示 p 值, min95 表示下 95% 置信区间, 
> max95 表示上 95% 置信区间.
> */ 

3.2 安慰剂检验

接下来,我们将搭配使用 aregstrmatchappenddpplot 等命令,进行 DID 估计中的安慰剂检验。本案例数据及代码来自南开大学经济学院毛其淋教授和方森辉助理研究员发表在 2020 年第 1 期《世界经济》上的文章,在此表示感谢!

*随机抽取并使用 parmest 保存回归 2000 次的结果
use data4_placebo_test, clear
global dep tfp_acf
global firm_control size lnage klr finance expdum soedum
global industry_control NPI_yeardum* LNF_yeardum* KLR_yeardum* EXP_yeardum*
global otherpolicy_control TARIN_yeardum* TAROUT_yeardum* SOE_yeardum* FOE_yeardum*

forv i=1/2000{
  qui areg $dep treat_post_false`i' $firm_control $industry_control ///
    $otherpolicy_control yeardum*, a(firmidbyBrandt2012JDE)         ///
    vce(cluster cic4byBrandt2012JDE)    
  parmest, format (estimate min95 max95 %8.2f p %8.3f) ///
    saving("placebo_test_result`i'.dta", replace)
  di `i'                                     
}

forv i=1/2000{
  append using "placebo_test_result`i'.dta" //纵向合并2000次随机抽取并回归的结果
}
keep if strmatch(parm, "treat_post_false*")==1 //保留2000个伪倍差法估计量的估计系数
di _N //通过观察样本量监控是否 2000 次抽取均得到了相应的估计结果
save placebo_test_result_all, replace

forv i=2/2000{
  erase "placebo_test_result`i'.dta" //删除中间文件以简化文件夹
}

*绘制安慰剂检验的图像
use placebo_test_result_all, clear //基准估计结果为 -0.037 见表 1 第 (3) 列
sum estimate, d                    //确定 5% 分位数为 -0.034 用于绘图使用
dpplot estimate, mcolor(red*1.5) msymbol(X) msize(small) xlabel(-0.06(0.02)0.06) ///
  xline(-0.037, lcolor(red*0.8) lwidth(0.4)) text(2 -0.045 "-0.037")             ///
  xline(-0.034, lcolor(red*0.8) lwidth(0.4) lpattern(dash_dot)) text(2 -0.026 "-0.034") ///
  ytitle("Probability Density") xtitle("Treat Effect Estimate") ///
  graphregion(color(white)) saving("Figure_3_Placebo_Test.gph", replace) 
//dpplot 命令用于绘制核密度图,并保存在 gph 格式文件
graph export "Figure_3_Placebo_Test.png", as(png) replace width(1920) height(1080) 
//以 png 格式输出图像并设置分辨率,用于直接插入 word 文档

4. 参考文献

  • 毛其淋, 方森辉. 外资进入自由化如何影响中国制造业生产率[J]. 世界经济, 2020, 43(01):143-169. -PDF-

5. 相关推文

Note:产生如下推文列表的 Stata 命令为:
lianxh 输出 安慰剂, m
安装最新版 lianxh 命令:
ssc install lianxh, replace

相关课程

免费公开课

最新课程-直播课

专题 嘉宾 直播/回看视频
最新专题 文本分析、机器学习、效率专题、生存分析等
研究设计 连玉君 我的特斯拉-实证研究设计-幻灯片-
面板模型 连玉君 动态面板模型-幻灯片-
面板模型 连玉君 直击面板数据模型 [免费公开课,2小时]
  • Note: 部分课程的资料,PPT 等可以前往 连享会-直播课 主页查看,下载。

课程主页

课程主页

关于我们

  • Stata连享会 由中山大学连玉君老师团队创办,定期分享实证分析经验。
  • 连享会-主页知乎专栏,700+ 推文,实证分析不再抓狂。直播间 有很多视频课程,可以随时观看。
  • 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标,输入简要关键词,以便快速呈现历史推文,获取工具软件和数据下载。常见关键词:课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法

连享会小程序:扫一扫,看推文,看视频……

扫码加入连享会微信群,提问交流更方便

✏ 连享会-常见问题解答:
https://gitee.com/lianxh/Course/wikis

New! lianxhsongbl 命令发布了:
随时搜索连享会推文、Stata 资源,安装命令如下:
. ssc install lianxh
使用详情参见帮助文件 (有惊喜):
. help lianxh