Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: construct new id variable


From   David Kantor <dkantor@jhu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: construct new id variable
Date   Wed, 10 Sep 2003 17:30:04 -0400

at 04:49 PM 9/10/2003 -0400, Oleksandr. wrote:
Dear statalist users,

I have a survey data with following variables:

familyid  personid  inwork
001         01            0
001         02            1
001         03            0
001         04            1
002         01            1
002         02            0

    Inwork is indicator of labor force partisipation. I want to create
variable "inworkid" that will be 0 if inwork=0 and will give numbers 1, 2,3
etc otherwise. In my example:

familyid  personid  inwork  inworkid
001         01            0            0
001         02            1            1
001         03            0            0
001         04            1            2
002         01            1            1
002         02            0            0

How can this be done?
There are many ways to do this. Here's one.

assert inwork==0 | inwork==1
gen long inworkid = sum(inwork)
replace inworkid =0 if inwork==0

(You may be able to reduce the last two commands to one, using cond.)

You did not indicate whether inworkid is to be calculated over the whole dataset, or by familyid.
If it is the latter, some adjustments can be made.
--David

David Kantor
Institute for Policy Studies
Johns Hopkins University
dkantor@jhu.edu
410-516-5404

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