Generating new variable

Generating new variable

by Eleni Jaswa -
Number of replies: 1

When generating a new variable (for example categorizing a continuous variable), it automatically assigns a group to missing data from the first. For example, when I say gen newvar [= 1 if oldvar >=10], it automatically assigns a "1" for missing data from the old var. Is there a way to keep the new data as missing when there is no data point from which to assign the new value?

In reply to Eleni Jaswa

Re: Generating new variable

by Kristen -

Yes, 

gen newvar = 1 if oldvar >=10 & oldvar !=.

replace newvar = . if oldvar==.