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
Seemingly Unrelated Regression with endogenous variablesCan I use Seemingly Unrelated Regression for system of equations in which I have an institutions var…
How to count the number of variables in multiple locals and meanwhile to compute the mean value of each group using for loop in Stata?As the title suggested, I would like to count the number of variables in multiple locals and meanwhi…
Esttab not giving the right outputHello, I am trying to create a table (4 columns and 3 rows) with names of states (variable state_na…
Occupation categoization according to STEM definitionHello stata community, I believe I'm having trouble coding the occupation of IPUMS CPS dataset acco…
ivprobit - very high wald chi2 - not the expected signsDear experts, Iam a bit lost in understanding what is going wrong with my model. Here is what I 've…
Subscribe to:
Post Comments (Atom)
0 Response to Using "if" and "and" commands while generating variables
Post a Comment