[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: panel data
Stata is very good at this kind of question.
Suppose your -employment- is a string variable.
bysort personal_number (year) : gen ever_selfemp = sum(employment == "self-emp")
by personal_number : gen first_selfemp = ever_selfemp == 1 & ever_selfemp[_n-1] != 1
by personal_number : replace ever_selfemp = ever_selfemp[_N] > 0
Now the number ever self-employed is given by
count if first_selfemp
and the histories of those ever self-employed are selected by
... if ever_selfemp
FAQ . . Creating variables recording whether any or all possess some char.
2/03 How do I create a variable recording whether any
members of a group (or all members of a group)
possess some characteristic?
FAQ . . . . . . . . . . . . . . . . . . . . . . . True and false in Stata
2/03 What is true and false in Stata?
SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step
Q1/02 SJ 2(1):86-102 (no commands)
explains the use of the by varlist : construct to tackle
a variety of problems with group structure, ranging from
simple calculations for each of several groups to more
advanced manipulations that use the built-in _n and _N
Andrey V. Ivanov
> Suppose I have the following data:
> personal_number employment year
> 1 perm 1997
> 1 perm 1998
> 2 un-Emp 1997
> 2 self-emp 1998
> 3 perm 1997
> 3 self-emp 1998
> 4 self-emp 1997
> 4 perm 1998
> Now, I want Stata to tell me how many people were
> self-employed in this
> data-set at SOME point in time. (3)
> Next, I also want stata to list the whole employment history
> of anyone who
> has been self-employed at SOME point in time.
> Could you please assist me?
* For searches and help try: