Statalist


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

Re: st:easy way to deal with "paired" variables?


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st:easy way to deal with "paired" variables?
Date   Sun, 1 Feb 2009 09:34:37 +0000 (GMT)

--- Mandy fu <[email protected]> wrote:
> The data set I'm working on includes 100 variables measuring the time
> spell of gaps between jobs. And for each gap there's a variable
> explaining why the person does not work during that gap. I want to
> calculate the total length of  any gaps caused by being in
> prison(reason=4) .

Problems like these can sometimes become a lot easier when the data is
transformed from a wide format to a long format. As you seem to want to
avoid creating a prison dummy, I used in the example below a logical
statement (reason==4) inside the -total- command. Logical statements
evaluate to 1 if true and 0 if false, so this statement plays the same
role as the dummies in your method.

*-------------- begin example --------------------
drop _all
input id gap1 reason1 gap2 reason2              
      1  30   1       20   2       
      2  25   2       180  4 
end  
list
reshape long gap reason, i(id) j(spell)
list
bys id : egen prisontime = total((reason==4)*gap)
list
*----------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


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