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!