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
Why is My Stata for-loop Code Wrong?I just want to compute descriptive statistics of the categorical time-invariant variables in the att…
Lasso variables selectionDear all, I have an unbalanced panel, where I have a bunch of dummies, bunch of categorical variab…
Generate a variable equal to 1 when a countryI'm sorry, my screen froze and I posted this topic by mistake. Here is the actual link : https://www…
TWFE for pooled cross sectionsHi, I currently have a dataset looking at 500 days, which is from 3rd April 2018 to 16th August 2019…
gen whole lot random variables (and random order) efficientlyHi all, One of the statistical computations that I've been working on involves assigning 10,000 col…
Subscribe to:
Post Comments (Atom)
0 Response to Using "if" and "and" commands while generating variables
Post a Comment