Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: how to get the mean value for this panel data?

 From Hey Sky To statalist Subject st: how to get the mean value for this panel data? Date Wed, 16 Feb 2011 18:36:53 -0800 (PST)

Dear Stataers

I have met a problem to calculate mean value in panel data. example data and
detail of my question as follows.

* example data
clear
input id jobid wage1 wage2 wage3
1 1 1 2 .
1 2 . 3 .
2 1 1 . .
2 2 . 2 2
3 1 1 2 .
3 2 . 3 .
3 3 . . 4
4 1 2 4 6
5 1 2 3 .
6 1 2 . 4
end

the wage1~3 represents the wages in each wave if the person works. for example,
the id=1 person works in 1st and 2nd wave but not 3rd. he switches job in 2nd
wave thus he has two wage for jobid=1, his first job. surely for id=2 person, he
has two jobs, switches job in 2nd wave and keeps it till 3rd wave. for id=4, he
keeps his job for all 3 waves and id=5 lost his only job in 3rd wave.

now, I need to get a mean wage for this 3 waves panel data. if they have not
switched job, use this job's wage in each wave to calculate the mean wage;
otherwise, use the new job wage in a new wave.

for example,for people who did not switch job, such as id=4, the mean wage
should equal to (2+4+6)/3, which egen x=rowmean(wage1 wage2 wage3) can do. but
how about id=1? his mean wage should equal to (1+3)/2; or id=2, mean
wage=(1+2+2)/3; and id=3, mean wage=(1+3+4)/3. how to have a code to deal with
all these situations automatically?

I have thousands obs in my real data. thus it is impossible to do it by hand.
thanks  for any suggestions.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/