Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: number of missing from previous year


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: number of missing from previous year
Date   Mon, 14 Aug 2006 12:19:08 +0100

The word "missing" is heavy with connotations. 

1. An observation can have a value for a given 
variable that is missing, meaning numeric missing
or string missing "" depending on the variable. 

2. Something can be omitted from, or not present
in, a dataset. 

What you want is neither of these. 

As I understand it, you want to count the people 
who left each firm in any given year. 

One logic is that if someone left a firm in 
a given year, then that was their last year
with the firm. 

Hence you can tag leavings with 

bysort firm personid (year): gen left = _n == _N 

except that you would not count someone as 
leaving who is still there in the last year
of record: 

bysort firm year : replace left = 0 if year == year[_N] 

Now you can count how many left each firm in 
each year. 

by firm year: egen number_left = total(left) 

tabdisp firm year, c(number_left) 

If you prefer to associate leavings with the next year, 

gen nextyear = year + 1 
tabdisp firm nextyear, c(number_left)

I don't know what you want to do about anybody
who left a firm and then came back to the same 
firm within the period of study. 

Nick 
n.j.cox@durham.ac.uk 

Wanli Zhao

> Thanks for the prompt help. My mistake to imply I only have 2 
> years data but
> actually I have 8 years. I think the change should be for 1994 because
> that's when the change occurs. In addition, this may be not 
> what I want
> because the code counts number of people change from firm to 
> firm. If a
> person retires and never appears in the data, then she is not 
> counted in the
> code I think, but should be. Again, I need to count the 
> missing persons from
> year to year. Could you help again?

Ada Ma
 
> bysort firm personid: gen count=_N if year==1993 | year==1994
> 
> * Count would equal to 2 if a person is with the same firm for both
> 1993 and 1994, 1 if this person was only with this firm in 1993 or in
> 1994.
> 
> bysort firm year: egen changed=total(count) if count==1 & year==1993
> 
> variable changed would contain the number of employees who were with
> this firm in 1993, but no longer remain employed with the same
> employer in 1994.  it'd be all missing values for this variable in
> 1994.
 
Wanli Zhao 

> > I have panel dataset, which has firm ID, year, and person ID for the
> people
> > working in the firm. I want to calculate the number of 
> staff changes for
> the
> > same company for each year. For example, the data is as follows.
> > FIRM YEAR   PERSONID
> > 1     1993   2
> > 1     1993   4
> > 1     1993   276
> > 1     1993   23456
> > 1     1993   853
> > 1     1994   2
> > 1     1994   276
> > 1     1994   853
> > 1     1994   3452
> > 1     1994   224
> >
> > I already sort firm and year. As you can see, the change of 
> staff for firm
> 1
> > in 1994 should be 2 because only person 2, 276 and 853 are 
> retained. I
> only
> > want to count how many persons are missing from previous year. 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index