Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: How do I save fixed panel effects as a variable


From   "Amy Dunbar" <Amy.Dunbar@business.uconn.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: How do I save fixed panel effects as a variable
Date   Fri, 31 Mar 2006 19:00:35 -0500

Thank you, Ada!  Your code worked.  I had to change a couple minor
things, but I now have a stata dataset with the permno and the related
fixed effect, which is a proxy for firm accounting conservatism.  I am
so happy!  Here is my code.

tsset permno yeara
xi: reg btm i.permno r0ret r1ret r2ret r3ret r4ret r5ret r6ret  i.yeara 
matrix permno_coef=e(b)'
svmat permno_coef
gen count=_n+1  
outsheet count permno_coef if count <=378 using permno.out, c replace
/* 378 firms, one is dropped in estimation */

use ahmed-br-8798, clear
drop if yeara>1993
sort permno year
gen count = _n
keep permno count
sort count
save countfirms1, replace

insheet count permno_coef using permno.out, clear 
gen conmkt = permno_coef * -1  /* conmkt = -alphai */
drop permno_coef
sort count
save countfirms2, replace

use countfirms1, clear  
sort count
merge count using countfirms2
drop _merge

save conmkt, replace

Amy Dunbar
University of Connecticut

------------------------------

Date: Fri, 31 Mar 2006 00:22:57 +0100
From: "Ada Ma" <heu034@googlemail.com>
Subject: Re: st: How do I save fixed panel effects as a variable

i have done something similar recently - i ran a model with roughly
400 dummies.  you said you're using fixed effects and used the -xtreg-
command.  but this isn't necessary as you already have i.permno.  if I
understand it correctly, running fixed effects is equivalent to having
a constant term for each of the group within permno.  therefore i
suggest that you use:

xi: reg btm i.permno r0ret r1ret r2ret r3ret r4ret r5ret r6ret i.yeara
matrix permno_coeff=e(b)'
svmat permno_coeff
outfile permno_coeff if _n<=499 using permno.out, c replace

i have no idea whether your permno variable is in sequence or not.  if
it is, then you might want to write:
gen count=_n
outfile count permno_coeff if _n<=499 using permno.out, c replace

note that i put the i.permno in front, so that the first 499
coefficients (500 - 1 for the ref group) would be the those that
corresponds to the permno's.  the OUT file can be easily read back
into Stata.  as long as you don't sort the data between you do the
- -svmat- and the -outfile- commands, the coefficients will stay in
sequence.

hope this helps!


- --
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926

------------------------------

Date: Fri, 31 Mar 2006 00:46:38 +0100
From: "Ada Ma" <heu034@googlemail.com>
Subject: Re: st: How do I save fixed panel effects as a variable

addendum to what i've said earlier.  it should be -outsheet- and not
- -outfile-.  and for more labour saving - assuming your permno variable
is a numeric variable, you might want to turn it into a string
variable.  you write:

encode permno, generate(permno1) label(permno1)
drop permno1

that turns the permno1 back into numeric but now the numeric variable
has a label!!!  as you can see I don't really care about the "permno1"
variable, all I want is to generate the label "permno1".

it's exciting because now after you have generate the count variable
(as I recommend in the earlier post), you can write:

label variable count permno1
decode count, generate(permno1)
outsheet permno1 permno_coeff if _n<=499 using permno.out, c replace

now count is a string variable, and because you outsheet it side by
side with permno_coeff, each of the coefficient will sit side by side
with a string variable that contains permno.  you would only need to
destring it again to turn it back into the original numeric.

it may sound rather cumbersome so if anyone have thought of better way
of doing this, plesae chip in.   cheers, ada

------------------------------

Date: Fri, 31 Mar 2006 00:52:30 +0100
From: "Ada Ma" <heu034@googlemail.com>
Subject: Re: st: How do I save fixed panel effects as a variable

still one more addendum (sorry!):

it should be:

gen count=_n-1

note the extra  "-1" in the equation.  now I'm assuming you're using
the first group as the ref group.  I'll shut up now.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index