1

I have a data set in which several observations have missing values, denoted by . (system missing).

For the observations that actually do have values, I want to make a dummy variable with the value 1 if the observations have a value; otherwise the dummy variable stays missing (I used gen dummy = .).

When I type replace dummy = 1 if variable > 0 it does indeed replace the dummy with 1, but for some reason it does for every observation, also those with a missing value.

How do I only replace it for the values which have a non-missing value?

Nick Cox
  • 56,404
  • 8
  • 127
  • 185
Paze
  • 2,291
  • Off-topic here. Please see advice on software-specific questions in the Help Center. This is intelligible to any Stata programmer even without a explicit self-contained example, so I have voted for migration to Stack Overflow. – Nick Cox Nov 29 '19 at 09:29
  • What do we use the stata tag for then? – Paze Nov 29 '19 at 10:09
  • We use the Stata tag when it is relevant, as flagging use of Stata code within a primarily statistical question. But the use of a tag is nothing much to do with whether a question is on-topic. A tag like economics would not mean, say, that a question purely about economics was on-topic here. https://stats.stackexchange.com/help/on-topic explains. – Nick Cox Nov 29 '19 at 10:15
  • All right thank you I'll keep that in mind. – Paze Nov 29 '19 at 10:47

1 Answers1

3

For Stata, missing has value equal to infinity.

Try: replace dummy = 1 if variable !=.

Nick Cox
  • 56,404
  • 8
  • 127
  • 185
  • Infinity here means a very large positive value larger than any other value and dependent on variable type, although precisely what value is usually immaterial to user and programmer alike. For that reason, variable < . is idiomatic for variable != .. – Nick Cox Nov 29 '19 at 09:24
  • Thanks, that explains it and also helps me in future configurations! – Paze Nov 29 '19 at 09:34