Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Conditional operatior trouble


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Conditional operatior trouble
Date   Mon, 15 Sep 2008 19:06:14 +0100

Apart from Maarten's pertinent comments, note that in Stata this could
be done like 
this, translating ? : to -cond(,)-  

gen week = 1 
gen dow = dow(stdate) 
replace week = cond(dow < dow[_n-1], week[_n-1] + 1, week[_n-1]) in 2/L 

Nick 
[email protected] 

Ashim Kapoor

I am having trouble with the last line of the following code  : -

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

gen week=1
gen dow=dow(stdate)

gen changeinweek=1 if dow< dow[_n-1]

replace week=( changeinweek==. ) ? week[_n-1] : week[_n-1]+1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

It says " invalid  ? "

Could someone please tell me what I am doing wrong ? In case someone
needs details I am assigning weeks to my data.

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