Bookmark and Share

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]

st: RE: RE: RE: RE: RE: column headings using estout


From   David Sikkink <David.Sikkink.1@nd.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: RE: RE: column headings using estout
Date   Thu, 7 Jun 2012 07:54:27 -0400

That is very cool code! Thanks, Lance. It works beautifully. 

I modified it for my variables and set of 3 nested models for each dependent variable. 

local ind2 "Female Age_Calculate Asian S_WAsian LatinFili Black OthRace Biracial" 
local ind3 "Female Age_Calculate Asian S_WAsian LatinFili Black OthRace Biracial Q85C1 Q85C2 biopar2o LiveLessBioM1 LiveLessBioF1 EducMHigh EducFHigh PushMhigh PushFhigh CivicMHigh CivicFHigh CathM1 CathF1 ConsProtM1 ConsProtF1 CathConsM1 CathConsF1 AttendMHigh AttendFHigh CloseMhigh CloseFhigh" 
local lab1 "School"
local lab2 "Demogs"
local lab3 "Parent"
local i = 1
foreach v of varlist revQ42A Create6day {
	forvalues j = 1/3 {
		_eststo m`i': reg `v' HS_Cath HS_IndCath HS_NonRel HS_Evg HS_Mainl HS_Homerel HS_Homenonr `ind`j''
		local mgroups "`mgroups' `e(depvar)'"
		local pattern "`pattern' 1"
		local mlabel "`mlabel' `lab`j''"
		local models "`models' m`i'"
		local ++i
	}
}
estout `models' using EstOutRegs1 , ///
	mgroups(`mgroups', pattern(`pattern')) ///
	mlabel(`mlabel') ///
	collabel(none) replace numbers  ///
	varlabels(HS_Cath Catholic HS_IndCath "Ind Cath." HS_NonRel Nonreligious HS_Evg "Evang. Prot." HS_Mainl Mainline HS_Homerel "Home relig." HS_Homenonr "Home nonrel.")

--David 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lance Erickson
Sent: Wednesday, June 06, 2012 6:36 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: RE: RE: column headings using estout

Here's what it might look like with two loops...

local ind2 "weight length"
local lab1 "origin"
local lab2 "physical"
local i = 1
foreach v of varlist price mpg rep78 {
	forvalues j = 1/2 {
		eststo m`i': reg `v' foreign `ind`j''
		local mgroups "`mgroups' `e(depvar)'"
		local pattern "`pattern' 1"
		local mlabel "`mlabel' `lab`j''"
		local models "`models' m`i'"
		local ++i
	}
}

Lance


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lance Erickson
Sent: Wednesday, June 06, 2012 3:51 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: RE: column headings using estout

If you're worried about accuracy and efficiency then I imagine you're working with some sort of loop. Aside from any statistical concerns I can imagine hearing from statalist members about working with that many outcomes, it really would be the way to go. Here's a solution that I think should work that local macros and a loop. Even this could be more efficient if you wanted to loop through sets of independent variables. I added another dependent variable just for kicks.


sysuse auto, clear

local i = 1
foreach v of varlist price mpg rep78 {

	eststo m`i': reg `v' foreign

	local mgroups "`mgroups' `e(depvar)'"
	local pattern "`pattern' 1"
	local mlabel "`mlabel' origin"
	local models "`models' m`i'"
	local ++i

	eststo m`i': reg `v' foreign weight length

	local mgroups "`mgroups' `e(depvar)'"
	local pattern "`pattern' 1"
	local models "`models' m`i'"
	local mlabel "`mlabel' physical"
	local ++i
}

estout `models', ///
	mgroups(`mgroups', pattern(`pattern')) ///
	mlabel(`mlabel') ///
	collabel(none)


Best,
Lance


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Sikkink
Sent: Wednesday, June 06, 2012 12:00 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: column headings using estout

Thanks, Lance. 

This gets me part of the way. The difficulty is that I have over 200 separate regressions in the do file (why I need that many is a long story, so to speak). 

As I understand your syntax, it is not directing estout to grab the dependent variable name for each regression but is providing the names directly for estout to use (in the mgroups command). I could do that, but it would be prone to error and tedious with the number of regressions that I am running. 

It looks like the same problem would apply to the mlabel command below. I need "origin" and "physical" to be "called" in a sense when the appropriate nested model is being run. Else I would have to string together "origin physical" over 100 times and stick the result in the mlabel command. It would work, but would not be as flexible as having a connection between the particular nested model being run and a particular heading. (In outreg2, this was easy to do using -estimates store Origin- and -estimates store Physical- etc., but -estimates store- and outreg2 does not work with -mi estimate, post-, and outreg2 has some issues dealing with a mix of different types of regressions, ologit, logit, reg, in the same output file.)

Thanks for your help. Your answer is giving me something to work with. Any other ideas?

--David

PS: Here is what I used to do in outreg2, and would like to do in estout (using "origin" and "physical" as examples). 

reg depvar1 indepvar1 indepvar2
estimates store Origin
reg depvar1 indepvar1 indepvar2 indepvar3 indepvar4 estimates store Physical
outreg2 [Origin Physical] using FileA 

reg depvar2 indepvar1 indepvar2
estimates store Origin
reg depvar2 indepvar1 indepvar2 indepvar3 indepvar4 estimates store Physical
outreg2 [Origin Physical] using FileA


This would append the results from the second depvar regressions to FileA, maintaining the depvar names as headers and the "origin" and "physical" as the subheadings for the appropriate nested regression. 


 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lance Erickson
Sent: Wednesday, June 06, 2012 12:18 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: column headings using estout

Hi David,

Here's one potential solution...


sysuse auto, clear

eststo m1: reg price foreign
eststo m2: reg price foreign weight length eststo m3: reg mpg foreign eststo m4: reg mpg foreign weight length

estout m1 m2 m3 m4, ///
	mgroups(price price mpg mpg, pattern(1 1 1 1)) ///
	mlabel(origin physical origin physical) ///
	collabel(none)



Best,
Lance




-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Sikkink
Sent: Wednesday, June 06, 2012 6:06 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: column headings using estout


I am running a series of nested regression models and storing the estimates using eststo. 

I would like to have a heading and subheading for each column of regression coefficients in the output from estout. I want the top heading to be the dependent variable name, and the subheading to indicate the particular nested model represented in the column (e.g., "Demographics", "Add Political Party" etc.). 

Multiple dependent variables will be run and included, but the subheadings will repeat for the nested regressions of each dependent variable. 

The result should look like this:

                      DepVar1                        DepVar1                         DepVar2                       DepVar2            
                      Demographics              Add Pol Party             Demographics           Add Pol Party
IndVar1              1.2                                   1.1                               .9                                     .8
IndVar2              3.2                                   2.8                              2.5                                  2.2
IndVar3                                                       .6                                                                         .3
IndVar4                                                      4.2                                                                       3.8


Thanks for any direction you can offer.

--David

*
*   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/

*
*   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/

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index