Announcement

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

  • Change observations values

    Hello, I recently started using STATA however I have a datset with approximately 7 million observations and about 30 variables, resulting from a merge of two datasets.
    I would like to update / replace the values of some observations that have been matched from Var1 according to the values of another variable Var2.
    As an example, imagine that for observation 1, the value of Var1 = 0.5 to Var2 = 10, however, I wanted to change it to Var1 = 2.55 to Var2 = 10.
    I emphasize that Var2 is a string and although I have done "encode" and try to use the resulting Var3 = 10 with the replace command it appears "(0 real changes made)". When I use "update Var1 = 2.55 if Var3 == 10" the error r (198) - invalid syntax appears.
    I would appreciate any help or tips. Thank you!

  • #2
    This is, at least partly, a very common misconception of what encode does. You either want destring or real(); find more on that in the very first paragraph of Description in

    Code:
    help encode

    Comment


    • #3
      Kate:
      welcome to this forum.
      You might have leading and/or trailing blanks in your -encode-d variables (see -string functions- entry in Stata .pdf manual).
      As an aside, using -encode- (instead of -dstring-) is not recommended if the -string- format variabke contains numbers (see -encode- entry in Stata .pdf manual for further details).
      Last edited by Carlo Lazzaro; 08 Jan 2021, 03:39.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thank you very much!

        Comment

        Working...
        X