Nick,
Thanks again. I learned a lot from the solutions.
Wanli
-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Tuesday, August 15, 2006 8:39 PM
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: number of missing from previous year
You can tag arrivals of each person at each firm by
. bysort firm personid (year) : gen byte arrivals = year != (year[_n-1] + 1)
This works for the first year of each panel too. Under -by:-
year[0], and thus year[0] + 1, will be missing, so the
inequality is true for the first year of each panel,
a panel here being defined by a firm and a person jointly.
You can tag departures of each person from each firm by
. bysort firm personid (year) : gen byte departures = year != (year[_n+1] -
1)
except that the last year of record for each firm
should be excluded
. bysort firm (year) : replace departures = 0 if year == year[_N]
Once you have tagged arrivals and departures by 1s and 0s,
you can add them up any way you want.
This is simpler, and more general, than my first proposal.
It is closer to David Cheong's approach, but you don't
need to loop, and -tsset- is not needed either.
Nick
n.j.cox@durham.ac.uk
Wanli Zhao
> Thank you so much, Nick. Most of the outcome is the same as
> David's. I think
> the difference lies in the count of persons who returned to
> the same firm
> later.
Nick Cox
> Now the closing verbal comment is wrong. This
> counts those who leave, return, ..., and then leave
> again just once for each firm.
Nick Cox
> > My code was wrong. I had
> >
> > bysort firm personid (year): gen left = _n == _N
> > bysort firm year : replace left = 0 if year == year[_N]
> > by firm year: egen number_left = total(left)
> > tabdisp firm year, c(number_l.eft)
> >
> > but it should have been
> >
> > bysort firm personid (year): gen left = _n == _N
> > bysort firm (year) : replace left = 0 if year == year[_N]
> > by firm year: egen number_left = total(left)
> > tabdisp firm year, c(number_left)
> >
> > Sorry about that.
> >
> > As flagged earlier, this counts those who leave even
> > if they return later in the panel.
> >
*
* 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/
*
* 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/