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

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

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

--- Mandy fu <> 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 
reshape long gap reason, i(id) j(spell)
bys id : egen prisontime = total((reason==4)*gap)
*----------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

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

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index