Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: TIME AVERAGE OF A DUMMY VARIABLE


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: TIME AVERAGE OF A DUMMY VARIABLE
Date   Thu, 08 Dec 2005 13:15:37 -0500

try using egen with the rowmean function

Rich Goldstein

[email protected] wrote:
Dear Statalisters,
I have a data set which is sorted by nr (person identification number) and
year(1980-1987).
I want to create a variable for the time average of a "married" which is a
time-varying dummy variable(taking a value of either zero or one). I have tried for instance:
sort nr, year
tsset nr, year
gen x=.
by nr year: replace
x=(married*d80+married*d81+married*d82+married*d83+married*d84+married*d85+m
arried*d86+married*d87)/8
The point is that I want to have the resulting average value NOT to be time
variant for each individual e.g: if say marital status is taking a value of
one for 4 years and zero for the remaining 4 years for a given individual I
want the resulting variable to take a value of 1/2 for each year for the
given individual.
I have tried many alternative specifications and although this seems fairly
easy in practice it turns out to be rather tricky.
Would be most grateful if someone could help!
Georgios
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index