# Re: st: number of missing from previous year

 From "Ada Ma" To statalist@hsphsun2.harvard.edu Subject Re: st: number of missing from previous year Date Sun, 13 Aug 2006 22:12:24 +0100

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

On 8/13/06, Wanli Zhao <zhaowl@temple.edu> wrote:
```
```Guys, please help me with a data management question. I spent a day and
cannot figure out.
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. I appreciate

Wanli

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

```
```
--
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926
*
*   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/
```