Dear Stata Experts,
I am trying to apply the code that Ben Jann provided for flipping the models and coefficients in a table of regression results made with his estout package.
The code is listed as "Approach 2" at http://repec.org/bocode/e/estout/advanced.html.
The code works very nicely in many situations, but it gets caught if I include factor variables in my regression command. I have provided an example below, which produces the error: 2bn.race invalid name r(198).
I know I could just create the dummy variables for race with tab, gen(), but it would be really nice if factor variables worked.
Does anyone know how to modify Ben's code to allow for factor variables?
Thanks,
Jeremy
I am trying to apply the code that Ben Jann provided for flipping the models and coefficients in a table of regression results made with his estout package.
The code is listed as "Approach 2" at http://repec.org/bocode/e/estout/advanced.html.
The code works very nicely in many situations, but it gets caught if I include factor variables in my regression command. I have provided an example below, which produces the error: 2bn.race invalid name r(198).
I know I could just create the dummy variables for race with tab, gen(), but it would be really nice if factor variables worked.
Does anyone know how to modify Ben's code to allow for factor variables?
Thanks,
Jeremy
Code:
*open some data sysuse nlsw88, clear *estimate some regressions eststo clear eststo wage: regress wage i.race eststo hours: regress hours i.race eststo ttl_exp: regress ttl_exp i.race eststo tenure: regress tenure i.race *make a table with estout esttab, b(2) not n r2 label nobase rename(_cons White) noomitted *use Ben's code to flip the table matrix C = r(coefs) matrix S = r(stats) eststo clear local rnames : rownames C local models : coleq C local models : list uniq models local i 0 foreach name of local rnames { local ++i local j 0 capture matrix drop b capture matrix drop se foreach model of local models { local ++j matrix tmp = C[`i', 2*`j'-1] if tmp[1,1]<. { matrix colnames tmp = `model' matrix b = nullmat(b), tmp matrix tmp[1,1] = C[`i', 2*`j'] matrix se = nullmat(se), tmp } } ereturn post b quietly estadd matrix se eststo `name' } local snames : rownames S local i 0 foreach name of local snames { local ++i local j 0 capture matrix drop b foreach model of local models { local ++j matrix tmp = S[`i', `j'] matrix colnames tmp = `model' matrix b = nullmat(b), tmp } ereturn post b eststo `name' }
Comment