Announcement

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

  • Rename numeric value to string ones

    Good morning, I have the following dataset
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(anno nasses)
    2018 201
    2018 201
    2018 201
    2018 233
    2018 215
    2018 233
    2018 235
    2018 235
    2018 203
    2018 201
    2018 201
    2018 201
    2018 201
    2018 201
    2018 201
    2018 216
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 201
    2018 233
    2018 233
    2018 206
    2018 206
    2018 215
    2018 232
    2018 235
    2018 235
    2018 235
    2018 233
    2018 235
    2018 216
    2018 203
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 209
    2018 209
    2018 209
    2018 235
    2018 235
    2018 206
    2018 215
    2018 215
    2018 216
    2018 219
    2018 235
    2018 235
    2018 215
    2018 235
    2018 216
    2018 219
    2018 201
    2018 215
    2018 203
    2018 216
    2018 201
    2018 215
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 215
    2018 232
    2018 235
    2018 201
    2018 201
    2018 201
    2018 201
    2018 201
    2018 201
    2018 235
    2018 235
    2018 203
    2018 215
    2018 235
    2018 235
    2018 216
    2018 235
    2018 235
    2018 235
    2018 235
    2018 235
    2018 201
    2018 201
    2018 201
    2018 201
    2018 235
    2018 235
    2018 219
    2018 201
    2018 201
    end
    how can I create a new variabel which has a Name associated to each numeric values? . Practically what I'm trying to do the opposite of these
    Code:
    recode country_mach (.=201) if Countryoforigin=="Albania"
    Thank you for your time

  • #2
    We can't see your Countryoforigin variable to check anything but you may be seeking


    Code:
    replace country_mach = 201 if Countryoforigin == "Albania"

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int(anno nasses) float Coutryname
      2018 201 .
      2018 201 .
      2018 201 .
      2018 233 .
      2018 215 .
      2018 233 .
      2018 235 .
      2018 235 .
      2018 203 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 216 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 201 .
      2018 233 .
      2018 233 .
      2018 206 .
      2018 206 .
      2018 215 .
      2018 232 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 233 .
      2018 235 .
      2018 216 .
      2018 203 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 209 .
      2018 209 .
      2018 209 .
      2018 235 .
      2018 235 .
      2018 206 .
      2018 215 .
      2018 215 .
      2018 216 .
      2018 219 .
      2018 235 .
      2018 235 .
      2018 215 .
      2018 235 .
      2018 216 .
      2018 219 .
      2018 201 .
      2018 215 .
      2018 203 .
      2018 216 .
      2018 201 .
      2018 215 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 215 .
      2018 232 .
      2018 235 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 235 .
      2018 235 .
      2018 203 .
      2018 215 .
      2018 235 .
      2018 235 .
      2018 216 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 235 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 201 .
      2018 235 .
      2018 235 .
      2018 219 .
      2018 201 .
      2018 201 .
      end
      Hi Nick in this case I don't want to insert the number but the name associated to a particoular number. The column Coutryname is empty and I wonder how can I fill it with the names of different countries associated to each number present in the variable nasses.
      The code I put previously doesn't refer to this dataset but to another where I did exactly the opposite: I had a varibale with the names of each states and I created a variable which contains the numeric values associated to each names.

      Comment


      • #4
        Now you're talking about yet another variable Coutryname or perhaps Countryname

        I can't follow confidently what you want here at all. Perhaps you need a file with numeric code and string name for each country and then need to merge it with this dataset.

        Comment


        • #5
          I'm sorry If I wasn't clear. I try to explain it better.
          If I have a varible (in this case nasses) with numeric values, how can I create a new variable which contain string values?
          In this particoular case the numbers present in nasses correspond to Coutries name which I'd like to be displayed in the variable Coutryname

          Comment


          • #6
            You need to type in strings as an extra variable or merge with a dataset with a string variable.

            Comment


            • #7
              Can you make me an example please? I'm not able to do it

              Comment


              • #8
                Hi I solved te problem I used this code
                Code:
                #delimit
                label define c_all
                
                201"Albania"
                205"Liechtenstein"
                209"Bulgaria"
                235"Romania"
                243"Ukraine"
                245"Russian Federation"
                252"Bosnia and Herzegovina"
                253"North Macedonia"
                254"Rep. of Moldova"
                256"Belarus"
                250"Croatia"
                270"Montenegro"
                271"Serbia and Kosovo: S/RES/1244 (1999)"
                272"Serbia and Kosovo: S/RES/1244 (1999)"
                301"Afghanistan"
                302"Saudi Arabia"
                304"Bahrain"
                305"Bangladesh"
                307"Myanmar"
                311"Sri Lanka"
                314"China"
                323"Philippines"
                324"Palestinian"
                327"Jordan"
                330"India"
                332"Iran (Islamic Rep. of)"
                333"Iraq"
                334"Israel"
                337"Lebanon"
                335"Kuwait"
                340"Malaysia"
                341"Mongolia"
                342"Nepal"
                344"Pakistan"
                348"Syrian Arab Rep."
                349"Thailand"
                351"Turkey"
                353"Viet Nam"
                354"Yemen"
                356"Kazakhstan"
                357"Uzbekistan"
                358"Armenia"
                359"Azerbaijan"
                360"Georgia"
                362"Tajikistan"
                361"Kyrgyzstan"
                401"Algeria"
                402"Angola"
                404"Cote d'Ivoire"
                406"Benin"
                409"Burkina Faso"
                410"Burundi"
                411"Cameroon"
                413"Cabo Verde"
                414"Central African Rep."
                415"Chad"
                417"Comoros"
                418"Congo"
                419"Egypt"
                420"Ethiopia"
                421"Gabon"
                422"Gambia"
                423"Ghana"
                425"Guinea"
                426"Guinea-Bissau"
                427"Equatorial Guinea"
                428"Kenya"
                430"Liberia"
                431"Libya"
                432"Madagascar"
                435"Mali"
                436"Morocco"   
                437"Mauritania"
                438"Mauritius"
                442"Niger"
                443"Nigeria"
                446"Rwanda"
                450"Senegal"
                451"Sierra Leone"
                453"Somalia"
                454"South Africa"
                455"Sudan"
                457"United Rep. of Tanzania"
                458"Togo"
                460"Tunisia"
                461"Uganda"
                463"Dem. Rep. of the Congo"
                465"Zimbabwe"
                466"Eritrea"
                467"South Sudan"
                514"Cuba"
                516"Dominican Rep."
                517"El Salvador"
                523"Guatemala"
                524"Haiti"
                525"Honduras"
                527"Mexico"
                529"Nicaragua"
                536"United States of America"
                602"Argentina"
                604"Bolivia (Plurinational State of)"
                605"Brazil"
                606"Chile"
                608"Colombia"
                609"Ecuador"
                614"Paraguay"
                615"Peru"
                619"Venezuela (Bolivarian Republic of)"
                999"Stateless";
                #delimit cr;
                label values State c_all

                Comment

                Working...
                X