Announcement

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

  • Renaming observations in string variable

    Hello! I have the variable statename which contains the names of different countries. This is a string variable so when using tab statename the values I obtain are of course words. I am looking to change some of these observations for example, changing the observation "Congo, Democratic Republic of (Zaire)" to "Democratic Republic of Congo". Thank you in advance!

  • #2
    An observation in Stata is, in other language, an entire row, record, case or item in a dataset.

    You can change the string values of a string variable with replace, as in

    Code:
    replace statename = "Democratic Republic of Congo" if strpos(statename, "Zaire")
    where I am guessing that no other observations contain "Zaire" as a substring. If in doubt then check beforehand

    Code:
    tab statename if strpos(statename, "Zaire")

    Comment


    • #3
      Originally posted by Nick Cox View Post
      An observation in Stata is, in other language, an entire row, record, case or item in a dataset.

      You can change the string values of a string variable with replace, as in

      Code:
      replace statename = "Democratic Republic of Congo" if strpos(statename, "Zaire")
      where I am guessing that no other observations contain "Zaire" as a substring. If in doubt then check beforehand

      Code:
      tab statename if strpos(statename, "Zaire")
      Thank you!

      Comment

      Working...
      X