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]
Re: st: generate regression coefficients as varaibles
From
Nahla Betelmal <[email protected]>
To
[email protected]
Subject
Re: st: generate regression coefficients as varaibles
Date
Wed, 9 Jan 2013 19:38:04 +0000
Hi,
Thank you for your kind reply, and the simplification.
I meant by not working is that i only managed to get the coefficients
for every year (y) but in each industry (SIC).
As I have 37 industries, I had to repeat the loop 37 times and hence
got 37 new variables for the constant coefficient instead of have one
constant variable that gathers the constant coefficients for all
industries in every year.
I was thinking about
gen coefficientCon=.
forvalue y=2001/2012 & i= 1/37 {
reg Wscaled Wone Wscaled_ch WPPE if sic== `i' & datayearfiscal==`y'
replace coefficientCon = _b[_cons] if datayearfiscal==`y' & sic==`i'
}
but I got : invalid syntax r(198);
Is there a way to make forvalues accept years `y' and industries `i'
simultaneously! if not, is there another way to do it?
Many thanks
Nahla
On 9 January 2013 18:37, Nick Cox <[email protected]> wrote:
>
> You don't explain what "is not working" means. This is crucial.
>
> Your code appears more complicated than needed, but I can't see a bug.
>
> gen coefficientCon=.
> forvalue y= 2001/2012{
> reg Wscaled Wone Wscaled_ch WPPE if dind1 & datayearfiscal==`y'
> replace coefficientCon = _b[_cons] if datayearfiscal==`y'
> }
>
> See also -statsby-.
>
> On Wed, Jan 9, 2013 at 6:30 PM, Nahla Betelmal <[email protected]> wrote:
> > Dear Statalist helpers,
> >
> > I am applying a cross sectional regression for 37 industries (i.e.
> > dind) over 11 fiscal years. I need to
> > extract the coefficients of each industry/year to substitute in a sub-sample.
> >
> > I tried this loop but it is not working:
> >
> > gen coefficientCon=.
> > forvalue y= 2001/2012{
> > reg Wscaled Wone Wscaled_ch WPPE if dind1 & datayearfiscal==`y'
> > scalar bvar=_b[_cons]
> > gen bvar=_b[_cons] if datayearfiscal==`y'
> > replace coefficientCon= bvar if datayearfiscal==`y'
> > drop bvar
> > }
> >
> > the out put I hope to get is silmilar to this in the edit file
> >
> > year industry coefficientCon coefficientb1 coefficientb2
> > 2001 dind1 0.2324 1,4356 8.98
> > 2002 dind1 0.654 1.445 3.98
> > .
> > .
> > 2011
> > 2001 dind2 0.343 .4344 2.3434
> > .
> > .
> *
> * 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/
*
* 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/