Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Re: Generate Variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Generate Variable
Date   Thu, 12 Mar 2009 12:32:14 -0000

Another approach: 

I infer panel structure with an identifier, and at most one measurement
for each -wavenum-. If that is so 

egen numProp4 = total((wavenum == 4) * numProp) , by(id) 

and 

egen numInsArrng6 = total((wavenum == 6) * numInsArrng) , by(id)

spread values in particular wave numbers to all observations with the
same identifier. For example, 

wavenum == 4 

is 1 if wavenum is 4 and 0 otherwise, so the ensuing total is just the
value of numProp for wavenum == 4. 

The required indicator variable follows directly. 

Note that even Erick's -if- condition had been correct (it isn't), his
expression for indicator (dummy in his terminology) would have yielded 1
and missing, not 1 and 0. 

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

Martin Weiss

More Income in 1982 than in 1980? Let`s see...

*********
clear*
inp id year sex inc
1 80 0 5000
1 81 0 5500
1 82 0 6000
1 83 0 7000
2 80 1 2000
2 81 1 2200
2 82 1 3300
2 83 1 3500
3 80 0 3000
3 81 0 2000
3 82 0 1000
3 83 0 1000
4 80 0 3000
4 81 0 4000
4 82 0 1000
4 83 0 10000
end
*mark years to compare
tempvar compare
g byte `compare'=year==80 | year==82
*sort them to the end, within id and respecting years, and generate 
indicators
bys id (`compare' year) : g byte hi82=inc[_N]>inc[_N-1]
*resort
sort id year
drop `compare'
*let`s see
l, noo sepby(id)

Erick Guerrero, M.A. (Ph.D. Candidate) 

> I am trying to create a dummy
> variable that is equal to 1 when organizations have more
> properties in wave 6 compared to wave 4. My data is in long
> form.
>
> Logically, it would be something like this, but this does not
> work, I am missing some steps.
>
> gen HiPropertyw6= 1 if (numProp==wavenum==4 <
> numInsArrng==wavenum==6).

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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