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 get excel file from dta file of data set, not results.Hello, I would like to change dta dataset to excel file(not result of analysis, but the data set as…
network rank min and sucra prob errorsHi , I am trying to generate a cumulative probability graph and rankograms for my network meta analy…
inspecting and comparing same variable content in relation to other variablePlease am new to stata and need help in extracting wrong inputs in a dataset. The data set contains …
wanting to run STATA via a websocketHi, I am setting up stata on a Linux server and am hoping there is a way to run stata using websocke…
output spearman correlationHello, I am trying to output spearman correlation matrix into rtf or excel using estpost but I am g…
Subscribe to:
Post Comments (Atom)
0 Response to Using "if" and "and" commands while generating variables
Post a Comment