Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Regression by year and industry to save coefficients and standard errors


From   "Alessandri, Todd" <T.Alessandri@neu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Regression by year and industry to save coefficients and standard errors
Date   Mon, 23 Dec 2013 16:27:14 +0000

Hello,
I am trying to run regressions by industry and year, and save the
coefficients and standard errors for each industry-year model as new
variables. There is an additional wrinkle‹I have panel data for 1998-2011
and want to run each regression using t to t-4 only (I.e., for 2001, use
only 1998-2001 years of data).

I am new to using foreach loops and I found some prior coding on the web.
I have tried to adapt it to my situation but two issues:

1. the code below generates an error message: "__000001 already defined"
2. I have not figured out how to use the rolling four year data periods.

Here is the code I tried. Any suggestions would be much appreciated.


use sic4calc
generate salescoeff= .  //empty variable for coefficient
generate salesstderr = . // empty variable for std error
tempvar salescoeff salesstderr // temporary variables for each regression
levelsof sic4, local(levels)
foreach x of local levels {
foreach z of numlist 2001/2011 {
capture reg logsic4sales fyear if sic4==`x' & fyear==`z'
generate `salescoeff' = _b[fyear] // coeff now in temp var
replace salescoeff = `salescoeff' if e(sample) // transfer coeff from temp
generate `salesstderr' = _se[fyear] // stderr now in temp var
replace salesstderr = `salesstderr' if e(sample) // transfer stderr from
temp
drop `salescoeff' `salestderr'
}
}
save sic4variables

Thanks,
Todd




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index