I have a numeric variable, say x. A lot of values are 0. The rest are all positive.
I want to create a new variable, which equals to 1 if x is 0, and which equals to x if x>0 (retaining values of x).
I tried this:
gen newx=1 if x=0 & newx=x if x>0
But it says invalid syntax.
Any way I can do this? Thanks!
Related Posts with Using "if" and "and" commands while generating variables
asdoc commandHello everybody, I am using this formula "asdoc estimates table est1 est2 est3 est4 est5 est6 est7, …
xteurostat (SSC) to download Eurostat information not working (?)Dear all, I have worked with xteurostat in the past and I have a nice Do-File which I was hoping to…
cmp procedure to fit a model with sample selection and non-random treatment assignmentHi all, I just came across a STATA procedure called “cmp”. I am wondering if the “cmp” procedure c…
No F-test valueHi, can anyone help me on how to deal with the problem of missing F-test value? Code: Multiple-i…
Estimating CES function three level (Borjas 2003) Hi, I look for thr means to build my database. Indeed in the context of my memory it will be quest…
Subscribe to:
Post Comments (Atom)
0 Response to Using "if" and "and" commands while generating variables
Post a Comment