# Re: st: TIME AVERAGE OF A DUMMY VARIABLE

 From "Michael Blasnik" To Subject Re: st: TIME AVERAGE OF A DUMMY VARIABLE Date Thu, 08 Dec 2005 13:39:57 -0500

Actually, I think he needs

by nr: egen x=mean(married)

because he wants the mean across observations within a panel. I think the dXX varies are year dummies, but there is one obs per id per year already.

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message ----- From: "Richard Goldstein" <richgold@ix.netcom.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Thursday, December 08, 2005 1:15 PM
Subject: Re: st: TIME AVERAGE OF A DUMMY VARIABLE

```try using egen with the rowmean function

Rich Goldstein

gmc107@york.ac.uk 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/
```