Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing an observation value for a variable in Stata

    Hi all,

    I would like to change an observation for a variable from one value to another but across the whole time series. For example, if the observation is coding for -66, how would I simply change this to code for missing? This -66 observation appears multiple times hence it would be inefficient to do by hand in say Excel.

    I have tried the
    Code:
    replace var1 = var1[6] if obsID==5
    command but Stata fails to recognise 'obsID'. I am not even certain that this is the correct code to be using for my desired results.

    Does anyone know how to do this?

    Many thanks!

  • #2
    If Stata fails to recognize "obsID" then use the -describe- command to make sure the spelling and capitalization is right. Stata variable names are case sensitive. But what do you mean by "coding for -66"? Is "-66" the missing value code used by the data provider, and now you want to use the Stata missing value code? I wonder what you think "var1[6]" is doing for you. In Stata that refers to the 6th record in the dataset. You say you want to change the value of vqr1 to missing, which would be:

    Code:
    replace var1 = . if var1==-66
    But then obsID is not consulted. Are you thinking that obsID is a system variable, perhaps the record number? It isn't and doesn't exist unless you provide it.

    Comment


    • #3
      Originally posted by [email protected] View Post
      If Stata fails to recognize "obsID" then use the -describe- command to make sure the spelling and capitalization is right. Stata variable names are case sensitive. But what do you mean by "coding for -66"? Is "-66" the missing value code used by the data provider, and now you want to use the Stata missing value code? I wonder what you think "var1[6]" is doing for you. In Stata that refers to the 6th record in the dataset. You say you want to change the value of vqr1 to missing, which would be:

      Code:
      replace var1 = . if var1==-66
      But then obsID is not consulted. Are you thinking that obsID is a system variable, perhaps the record number? It isn't and doesn't exist unless you provide it.
      Hi Feenberg,

      thanks for the solution - that was exactly what I was trying to do. You are correct, -66 was the code given to missing data by the data provider.

      Comment

      Working...
      X