Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Dominik Becker <dombecksoz@googlemail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: estout: flipping and matching models |

Date |
Thu, 9 Sep 2010 12:30:01 +0200 |

One week ago a posted a message wherein I asked how I could achieve that for a set of regressions with changing treatments, but a similar structure for each treatment (i.e. with and without covariates, respectively), the coefficients of the treatments are both flipped and in the same lines after flipping. In personal communication with Ben Jann, the author of -estout- and related routines, we found that the example code that I attached to my original post was erroneous. So first of all sorry to all listers who might have tried to help me but could not run my example! Ben suggested that the easiest way to solve my problem would be to stack the models first by using his -append- routine (also available at http://repec.org/bocode/e/estout/advanced.html#advanced901) and then to flip the models by collecting the r(coefs) of estout and transposing them (see http://repec.org/bocode/e/estout/advanced.html#advanced907). This works fine except for multiple-equation models since the -append- command explicitly only makes use of the first equation of a model - even if there are more. So I asked Ben if there is a possibility to extract single equations of multiple-equation models like -seqlogit- (a user-written program by Maarten Buis) either in -append- or before in -estimates store-. Ben replied that both issues are on his list for later revisions of his routines, but he can already offer a quick hack to extract the equations in -estimates store-. Since this approach might be of interest for some more users, I below attach a (well-tried) example code with Ben's solutions how to extract single equations from a set of similar -seqlogit- commands with changing treatments, how to stack the models, and to flip them. Many thanks again to Ben Jann for his personal support and his very practical solutions! Dominik ----------------------------------BEGIN OF CODE ----------------------------------------------- ssc install seqlogit // if not already installed *** RECODE COMMANDS FROM SEQLOGIT HELPFILE *** sysuse nlsw88, clear gen ed = cond(grade< 12, 1, /// cond(grade==12, 2, /// cond(grade<16,3,4))) if grade < . gen byr = (1988-age-1950)/10 gen white = race == 1 if race < . *** PROGRAM TO EXTRACT EQUATIONS *** ssc install erepost // is used in -eqextract- capt prog drop eqextract prog eqextract version 8.2 syntax [, k(int 1) ] tempname b V mat `b' = e(b) mat `V' = e(V) local eqs: coleq `b', quoted local eqs: list uniq eqs local eq: word `k' of `eqs' mat `b' = `b'[1..., "`eq':"] mat `V' = `V'["`eq':", "`eq':"] erepost b = `b' V = `V' end ***** SEQUENTIAL LOGIT MODELS ***** *** TREATMENT 1 *** * WITHOUT CONTROL * seqlogit ed byr, /// ofinterest(white) /// tree(1 : 2 3 4, 2 : 3 4, 3 : 4) /// or estimates store t1a eqextract estimates store t1a1 estimates restore t1a eqextract, k(2) estimates store t1a2 estimates restore t1a eqextract, k(3) estimates store t1a3 * WITH CONTROL * seqlogit ed byr south, /// ofinterest(white) /// tree(1 : 2 3 4, 2 : 3 4, 3 : 4) /// or estimates store t1b eqextract estimates store t1b1 estimates restore t1b eqextract, k(2) estimates store t1b2 estimates restore t1b eqextract, k(3) estimates store t1b3 *** TREATMENT 2 *** * WITHOUT CONTROL * seqlogit ed byr, /// ofinterest(union) /// tree(1 : 2 3 4, 2 : 3 4, 3 : 4) /// or estimates store t2a eqextract estimates store t2a1 estimates restore t2a eqextract, k(2) estimates store t2a2 estimates restore t2a eqextract, k(3) estimates store t2a3 * WITH CONTROL * seqlogit ed byr south, /// ofinterest(union) /// tree(1 : 2 3 4, 2 : 3 4, 3 : 4) /// or estimates store t2b eqextract estimates store t2b1 estimates restore t2b eqextract, k(2) estimates store t2b2 estimates restore t2b eqextract, k(3) estimates store t2b3 ******* PROGRAM TO APPEND MODELS ***** capt prog drop appendmodels *! version 1.0.0 14aug2007 Ben Jann program appendmodels, eclass // using first equation of model version 8 syntax namelist tempname b V tmp foreach name of local namelist { qui est restore `name' mat `tmp' = e(b) local eq1: coleq `tmp' gettoken eq1 : eq1 mat `tmp' = `tmp'[1,"`eq1':"] local cons = colnumb(`tmp',"_cons") if `cons'<. & `cons'>1 { mat `tmp' = `tmp'[1,1..`cons'-1] } mat `b' = nullmat(`b') , `tmp' mat `tmp' = e(V) mat `tmp' = `tmp'["`eq1':","`eq1':"] if `cons'<. & `cons'>1 { mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1] } capt confirm matrix `V' if _rc { mat `V' = `tmp' } else { mat `V' = /// ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ /// ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' ) } } local names: colfullnames `b' mat coln `V' = `names' mat rown `V' = `names' eret post `b' `V' eret local cmd "whatever" end ***** APPENDING SIMILAR MODELS FOR EACH EQUATION ***** *** EQ 1 *** * NO CONTROL * eststo eq1_nc: appendmodels t1a1 t2a1 * WITH CONTROL * eststo eq1_wc: appendmodels t1b1 t2b1 *** EQ 2 *** * NO CONTROL * eststo eq2_nc: appendmodels t1a2 t2a2 * WITH CONTROL * eststo eq2_wc: appendmodels t1b2 t2b2 *** EQ 3 *** * NO CONTROL * eststo eq3_nc: appendmodels t1a3 t2a3 * WITH CONTROL * eststo eq3_wc: appendmodels t1b3 t2b3 ***** ESTOUT WITH FLIPPING ***** *** SEPARATE TABLES *** * EQ 1 * estout eq1_nc eq1_wc, keep(white union) mat list r(coefs) estout r(coefs, transpose) * EQ 2 * estout eq2_nc eq2_wc, keep(white union) mat list r(coefs) estout r(coefs, transpose) * EQ 3 * estout eq3_nc eq3_wc, keep(white union) mat list r(coefs) estout r(coefs, transpose) *** SINGLE TABLE *** estout eq1_nc eq1_wc eq2_nc eq2_wc eq3_nc eq3_wc, keep(white union) mat list r(coefs) estout r(coefs, transpose) --------------------------------------END OF CODE----------------------------------------------------- 2010/9/2 Dominik Becker <dombecksoz@googlemail.com>: > Dear listers, > > Suppose, I want to run several regression models with changing > treatments and both with and without a covariate which is the same > across models. Further assume that I want to flip the regression > table, because I will have more models than treatments, and I would > like to display the former in rows rather than in columns: > > -------------------------------------------------------------------------- > sysuse auto, clear > > regress price weight > estimates store t1a, title("without controls") > > regress price weight mpg > estimates store t1b, title("with controls") > > regress price length > estimates store t2a, title("without controls") > > regress price length mpg > estimates store t2b, title("with controls") > > mat list r(coefs) > estout r(coefs, transpose) > ---------------------------------------------------------------------- > > How can I achieve that the the coefficients for t1a and t2a, and those > for t1b and t2b are displayed in the same row, respectively? I also > tried: > > estout r(coefs, transpose), rename(t2a t1a t2b t1b) > > to match the models (as recommended for coefficients on > http://repec.org/bocode/e/estout/advanced.html#advanced008), but > unfortunately, this did not work. > > Thanks for any suggestions! > Dominik > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: estout: flipping and matching models***From:*Dominik Becker <dombecksoz@googlemail.com>

- Prev by Date:
**st: Stata 11 .1 do editor** - Next by Date:
**st: survival analysis with unknown censoring** - Previous by thread:
**st: estout: flipping and matching models** - Next by thread:
**st: box and whisker plot with proportional box size?** - Index(es):