Statalist


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

RE: st: RE: calculating number of bimesters


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: calculating number of bimesters
Date   Wed, 17 Dec 2008 17:33:13 -0000

Your codes look messy, but the problem is tractable so long as you take it in slow small steps: 

The correspondence is 

phase  bimester 

16       4 
17       5 
20       2 
21       4 
22       5 
23       6 

So, you can do that a longer way or a shorter one: 

gen bimester0 = 4 if phase == 16 | phase == 21 
replace bimester0 = 5 if phase == 17 | phase == 22 
replace bimester0 = 6 if phase == 23 
replace bimester0 = 2 if phase == 20 

I can't see any gain in clarity in packing this into one command, but it could be done: 

gen bimester0 = cond(phase == 20, 2, 
                cond(phase == 16 | phase == 21, 4, 
	          cond(phase == 23, 6, 
                cond(phase == 17 | phase == 22, 5
                 )))) 

That's all one line. It may get messed up between my mailer and yours. 

Note that 

inlist(phase, 16, 21) 

is another way of writing 

phase == 16 | phase == 21 

but the choice is yours. 

A tutorial on -cond()- by David Kantor and myself is accessible to all at 

<http://www.stata-journal.com/sjpdf.html?articlenum=pr0016>

-- but it's not compulsory. 

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

Rodrigo Briceño

Nick, after trying your solution I discovered that instead of the
values 1=july-august 2002, 2=sep-oct 2002, 3=mar-apr 2004, 4=jul-aug
2004, 5=sep-oct 2004, and 6=nov-dic 2004, I have the values 16, 17,
20, 21, 22, 23. In that case I changed your commands in this way:

gen year0 = cond(phase < 20, 2002, 2004)

The doubt here is which values corresponds to the second and third
lines of command:

gen bimester0 = cond(phase < 3, phase + 3, cond(phase == 3, 2, phase))
(do I need to change the 3 for 20?, not sure about it

gen mytime = 6 * (year - year0) + (bimester - bimester0) + 1

any help is appreciated.


*
*   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