添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Dear Statalisters,
I am trying to add some postestimation results from lincom to a regression table using esttab (from SJ). For this I use lincomest (from SSC) which stores the estimation results. What I would want is to have the lincomest results below the coefficients of the regression. I have tried using estadd but haven't managed to get it to work so far. Is this possible? I'm trying to avoid using scalars because then it is impossible to add significance stars.
Code:
sysuse auto, clear
eststo: reg price c.mpg##foreign
eststo: lincomest _b[mpg] + _b[1.foreign#c.mpg]
esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3)))
--------------------------------------
                      (1)          (2)
                    price        price
                     b/se         b/se
--------------------------------------
mpg              -329.255            
                   74.985            
1.foreign         -13.587            
                 2634.664            
1.foreign#~g       78.888            
                  112.481            
(1)                           -250.367
                                83.840
_cons           12600.538            
                 1527.888            
--------------------------------------
N                      74           74
--------------------------------------
I'm trying to avoid using scalars because then it is impossible to add significance stars this is not true. Here, what matters is sequence because you want the lincom results to be linked to your regression estimates, and you can only obtain the lincom results after the regression. This suggests that you need to run the regression at least twice, which is what I do below. With Stata's margins command, you no longer need lincomest from SSC.
Code:
sysuse auto, clear
qui reg price c.mpg##foreign
margins, expression(_b[mpg] + _b[1.foreign#c.mpg]) post
mat r= r(table)
eststo: reg price c.mpg##foreign
estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", ///
cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", ///
cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*",  "`:di %5.3f `=r[1,1]''")))'"
esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3))) scalar("mystat My stat")
Res.:
Code:
. esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3))) scalar("mystat My stat")
-------------------------
                    price
-------------------------
mpg              -329.255
                   74.985
1.foreign         -13.587
                 2634.664
1.foreign#~g       78.888
                  112.481
_cons           12600.538
                 1527.888
-------------------------
N                      74
My stat       -250.367***
-------------------------
Dear Andrew,
how can I produce a similar table as you show in post 2, however if I have two or mor einteraction terms?
Thank you! Hi Andrew, would you have any suggestions on how to include the SE in parenthesis for the linear combination from post 2? And to move these results to be located above the regression stats (r2 etc)?
Thank you. sysuse auto, clear reg price c.mpg##foreign xlincom lin_com = _b[mpg] + _b[1.foreign#c.mpg], repost esttab, nogaps nobase eqlabels("Main" "Linear combinations", span) Wouter Wakker thanks for the response. Does this package work for Stata 16?
I seem to get an error message when trying your code.
xlincom lin_com = _b[mpg] + _b[1.foreign#c.mpg], repost
lin_com: _b[mpg] + _b[1.foreign#c.mpg] = 0
foreign#co: operator invalid
r(198);
end of do-file
Would you know why this is?
added macro:
             e(mystat) : "-0.115***"
but the outreg2 doesn't read the e(mystat) value in the addstat section. It gives me an error saying `invalid syntax'. Any idea on how I can fix this? My end goal is to have both coeffient and associated significance stars in the same cell, exactly like it is shown in e(mystat)
reghdfe att treat ebola treat_ebola if year==0, vce(robust) noabsorb
lincomest treat + treat_ebola
mat r= r(table)
matrix list r(table)
estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*", "`:di %5.3f `=r[1,1]''")))'"
outreg2 using table_a3, dec(3) nonotes nocons tex replace addstat(Attrition for Ebola=1, `e(mystat)') keep(treat treat_ebola) label Hi Andrew Musau there seems to be a problem
The code works fine but it no longer reports the treat_ebola coefficient in the second regression. I am pasting my full code below.
// Reg 1
reghdfe att treat if year==0, vce(robust) noabsorb
outreg2 using table_a3, replace dec(3) adjr2 nonotes tex label
// Reg 2
reghdfe gender treat ebola treat_ebola if year==0, vce(robust) noabsorb
lincomest treat + treat_ebola
mat r= r(table)
estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*", "`:di %5.3f `=r[1,1]''")))'"
outreg2 using table_a3, dec(3) nonotes nocons tex append addtext(Attrition for Ebola=1, `e(mystat)') keep(treat treat_ebola) label
I want something like this (figure below) with starts on "Attrition for Ebola=1"
with the code above what I get is as follows (figure below)
* Example generated by -dataex-. For more info, type help dataex
clear
input float(year att) double(treat gender) float(ebola treat_ebola)
0 0 0 0 0 0
0 0 1 0 1 1
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 1 1 1
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 1 1
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 1 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 1 1
0 0 0 0 0 0
0 0 0 1 1 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0
0 1 0 1 1 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 1 1
0 0 1 1 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 1 0 0 0
0 0 1 0 1 1
0 0 1 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 1 0 1 1
0 0 0 0 1 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 1 1 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 0 0 0 1 0
0 0 1 0 1 1
0 0 0 0 1 0
0 0 1 0 1 1
0 0 0 0 1 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 1 0 0
0 0 1 0 1 1
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 1 0 0 0
0 0 1 0 1 1
0 0 0 0 0 0
label values year year
label def year 0 "2015", modify
label values att att
label def att 0 "Retained", modify
label def att 1 "Attrited", modify
label values treat treat
label def treat 0 "Control", modify
label def treat 1 "Treatment", modify
label values gender gender
label def gender 0 "Female", modify
label def gender 1 "Male", modify