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   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: TIME AVERAGE OF A DUMMY VARIABLE
Date   Thu, 8 Dec 2005 18:29:14 -0000

It doesn't sound to me as if -rowmean()- is what 
you want. 

You want to know over what 
fraction of a period each person was married. 

That is 

egen fr_married = mean(married), by(nr) 

Then you can combine that with whatever else
you want. 

Nick 
[email protected] 

Richard Goldstein
 
> try using egen with the rowmean function

[email protected] 

> > 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.

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