Reputation: 1
The treatment boroughs are five boroughs with ID 1, 2, 3, 6, 14. The “Operation Theseus" policy lasts from week 80 to week 85.
ocu
: borough ID
I tried creating dummies of treated
and time
but they just show as zero for all
gen treated =0 if missing(ocu)==0
replace treated =1 if ocu==1/2/3/6/14
gen time = (week==80-85) & !missing(week)`
Upvotes: 0
Views: 87
Reputation: 37358
ocu == 1/2/3/6/14
is a legal expression, but is likely to be a long way from what you want.
occ == 1 | occ == 2 | occ == 3 | occ == 6 | occ == 14
is legal and long-winded and
inlist(occ, 1, 2, 3, 6, 14)
legal and likely to be appealing as an expression for: does occ
take on any the values specified?
Although Stata supports |
as an "or" operator (and not /
for that purpose) note that
occ == 1 | 2 | 3 | 6 | 14
is legal but almost never what anyone would want, as it is parsed
(occ == 1) | 2 | 3 | 6 | 14
and will always be evaluated 1 (true), regardless of the value of occ
, as just one of the other arguments 2 3 6 14 being non-zero means that the entire expression evaluates to 1 (true).
The expression week==80-85
is also incorrect syntax if you want it to mean week
between 80 and 85. Stata will evaluate week == 80-85
, applying the subtraction first and so test for equality with -5. See precedence rules as documented in help operators
.
The order of evaluation (from first to last) of all operators is ! (or ~), ^, - (negation), /, *, - (subtraction), +, != (or ~=), >, <, <=, >=, ==, &, and |.*
Subtraction comes before testing for equality.
You may want week >= 80 & week <= 85
or inrange(week, 80, 85)
.
If week
is between 80 and 85, then it can't be missing. That test is redundant (but harmless).
Upvotes: 1