Reputation: 3897
I am using the community-contributed command estout
to output a customized table from Stata to a latex .tex
file. However, I do not know how I can add multiple columns in one table.
Below is a simplified example where I create two separate tables, each containing the standard deviations of the residuals from two different regressions:
reg y x1
predict res1, residual
reg y x2
predict res2, residual
reg y x3
predict res3, residual
reg y x4
predict res4, residual
eststo clear
estpost summarize res1 res2
eststo
esttab, cells("sd") noobs nonum
esttab using first.tex, cells("sd") noobs nonum replace
eststo clear
estpost summarize res3 res4
eststo
esttab, cells("sd") noobs nonum
esttab using second.tex, cells("sd") noobs nonum replace
However, I would like to have the two columns in the same table as follows:
sd(res1) sd(res3)
sd(res2) sd(res4)
Is Stata 14 capable of customizing a table like this?
This question is different from this question in that there I was looking for the command which creates customized tables. The answer was estpost
. Now, I am asking for customization of this command in a way that I couldn't find in its documentation.
Upvotes: 1
Views: 600
Reputation:
You need to create a matrix with the results and then configure estout
's options accordingly:
sysuse auto, clear
regress price mpg
predict res1, residual
regress price length
predict res2, residual
regress price displacement
predict res3, residual
regress price headroom
predict res4, residual
matrix A = J(2, 2, 0)
local j = 0
forvalues i = 1 / 4 {
summarize res`i'
if `i' <= 2 matrix A[`i', 1] = r(sd)
else {
local ++j
matrix A[`j', 2] = r(sd)
}
}
esttab matrix(A), mlabels(sd) collabels(none) coeflabels(none)
--------------------------------------
sd
--------------------------------------
2605.621 2562.891
2660.311 2930.096
--------------------------------------
Upvotes: 2