I've now been searching around for quite some time but am just not able to find answers to my specific needs.
I want to create a very individualized table in order to compare one coefficient over different models, outcomes and years.
The idea is to get a table in latex with four different outcomes (o1, o2, o3, and o4) for which I run different models (OLS and IV for o1, for o2 and so on).
These are supposed to be my columns.
In the rows, I want to reproduce this for different years, let's say 2000, 2005, 2010 and 2015.
As the regressions take a while to run, i stored the estimates using "estimates store"
Until now, what I did is just take the coefficients of my saved results, put them into a matrix and then esttab that matrix.
The code looks something like this:
Code:
* Load the results
foreach var in o1 o2 o3 o4 {
forvalues i = 1/2 {
estimates use "$results\estimations.est", number(`i')
estimates store `var'_`i'_2015
}
}
* Create an empty matrix
matrix table1 = J(8,8,.)
* Fill up the matrix with OLS and IV results for 2015 in row one
local i = 1
foreach var in o1 o2 o3 o4 {
estimates restore `var'_1_2015
matrix table1[1,`i'] = _b[coef1]
matrix table1[2,`i'] = (_se[coef1])
estimates restore `var'_2_2015
matrix table1[1,`i'+1] = _b[coef1]
matrix table1[2,`i'+1] = (_se[coef1])
local i = `i' + 2
}
* Then repeat this procedure for years 2000-2010
* ...
mat rownames table1 = "2015" "se" "2010" "se" "2005" "se" "2000" "se"
* Create table:
esttab matrix(table1, fmt(a3)) using "$tables\table1.tex", replace ///
collabels("o1 OLS" "o1 IV" "o2 OLS" "o2 IV" "o3 OLS" "o3 IV" "o4 OLS" "o4 IV") ///
cells(_star) nomtitles ///
substitute("\begin{tabular}{l*{8}{c}}" "\begin{table}[H]\centering \caption{Regressions in different years} \label{table:years} \begin{adjustbox}{max width=\textwidth} \begin{tabular}{l*{8}{c}}" ///
"\end{tabular}" "\end{tabular} \end{adjustbox} \end{table}" "(.)" "" " 0 " "" ///
"& o1 OLS& o1 IV& o2 OLS& o2 IV& o3 OLS& o3 IV& o4 OLS& o4 IV" ///
"& \multicolumn{2}{c}{\underline{o1}} & \multicolumn{2}{c}{\underline{o2} } & \multicolumn{2}{c}{\underline{o3}} & \multicolumn{2}{c}{\underline{o4}} \\ & OLS & IV & OLS & IV & OLS & IV & OLS & IV ")
Thank you in advance!
0 Response to Individual tables using esttab/estout
Post a Comment