Announcement

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

  • Replace if, with str3 variables

    Hey guys,

    what I want to do is pretty striaghtforward. I would like to replace 3-digit country codes by 2-digit country codes. My 3-digit country codes are strings (str3) with format (%9s). Due to some research I came up with the following code.

    Code:
    replace reporteriso = string("AE","%9s") if reporteriso == string("ARE", "%9s")


    However there is still type mismatch due to error 109.


    Many thanks in advance!

  • #2
    Assuming that these are standard three letter country codes, then the easiest solution for you would be to look at kountry on SSC. Type in Stata ssc desc kountry. That program will do the conversion of all codes in one command, saving you a lot of typing (and, if you are like me, a lot of typos).

    If that does not work for you, then you can do the recoding manually:

    Code:
     replace reporteriso = "AE" if reporteriso == "ARE"
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks for your answer. That leads me to the next problem. How do I merge it with the data in my memory? I'm particularly interested in the k_iso2c.ado file.
      Many thanks!

      Comment


      • #4
        I don't understand that question. Are you asking how to use kountry? You don't use k_iso2c.ado directly, you let kountry take care of that. In general you install it (ssc install kountry), you open the help file (help kountry), and then do what the help file tells you. In your case it is probably kountry reporteriso , from(iso3c) to(iso2c). But since I don't have access to your data, I am guessing.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X