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
How to call the stored results in e()?I am using did_imputation and I read over the help file. I saw a part about the result regarding Sto…
Counting unique no missing valuesHi! My dataset is about trust in government and media. It contains two variables: 1. city- the code …
Panel data: Calculate change within each subgroup from the first to the last observation (over time)Hi, I work on unbalanced panel data (26 states ("cant"), time period around 1970-2017) on wealth sh…
Problems with logistic regression resultsI used stata to run logistic regression, but stata gives the following information: " note: DX != 0…
forval with a variableHello everyone. I am new to Stata. I need your help for a short question. I have a dataset, and I ho…
Subscribe to:
Post Comments (Atom)
0 Response to Using "if" and "and" commands while generating variables
Post a Comment