Announcement

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

  • creating universal ID and assign them

    Hello,

    I am building a bilateral dataset on trade measures that countries take against one another. As you can see in the example, each observation consists of an Imelepemnting Jurisdiction (country) + its ID and affected Jurisdiction (country) + its ID. Obviously, the ID for each country must be consistent across the dataset. For example, if Aghanistan has ID=1 as an implementing country, it must also have the same ID if it is affected.
    I created a unique ID for each country by
    encode ImplementingJurisdiction, gen(country)

    But I do not know how to use it or assign it as a variable (let's say "countryid_Affctd") as a column sided by the Affected county (or affected Jurisdiction)


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float countryid_implmt long Impl_Jur float countryid_Affctd long Aff_Jur float(year countryid) long country
    . 1 .   . 2008 . .
    . 1 .   . 2009 . .
    1 1 . 148 2010 1 1
    1 1 . 154 2010 1 1
    1 1 . 148 2011 1 1
    1 1 . 154 2011 1 1
    1 1 . 148 2012 1 1
    1 1 . 154 2012 1 1
    1 1 . 154 2013 1 1
    1 1 . 148 2013 1 1
    1 1 . 148 2014 1 1
    1 1 . 154 2014 1 1
    1 1 . 148 2015 1 1
    1 1 . 154 2015 1 1
    1 1 . 148 2016 1 1
    1 1 . 154 2016 1 1
    1 1 . 148 2017 1 1
    1 1 . 154 2017 1 1
    1 1 . 154 2018 1 1
    1 1 . 148 2018 1 1
    1 1 . 154 2019 1 1
    1 1 . 148 2019 1 1
    1 1 . 154 2020 1 1
    1 1 . 148 2020 1 1
    . 1 .   . 2021 . .
    . 1 .   . 2022 . .
    . 1 .   . 2023 . .
    . 1 .   . 2024 . .
    . 1 .   . 2025 . .
    . 1 .   . 2028 . .
    . 1 .   .    . . .
    . 2 .   . 2008 . .
    2 2 .  76 2009 2 2
    2 2 . 213 2009 2 2
    2 2 . 166 2009 2 2
    2 2 . 118 2009 2 2
    2 2 .  98 2009 2 2
    2 2 .  78 2009 2 2
    2 2 .  42 2009 2 2
    2 2 . 221 2009 2 2
    2 2 .  92 2009 2 2
    2 2 .  98 2010 2 2
    2 2 .  92 2010 2 2
    2 2 .  76 2010 2 2
    2 2 . 166 2010 2 2
    2 2 . 221 2010 2 2
    2 2 .  78 2010 2 2
    2 2 . 118 2010 2 2
    2 2 . 213 2010 2 2
    2 2 .  42 2010 2 2
    2 2 .  42 2011 2 2
    2 2 .  78 2011 2 2
    2 2 .  92 2011 2 2
    2 2 . 118 2011 2 2
    2 2 . 166 2011 2 2
    2 2 .  98 2011 2 2
    2 2 . 221 2011 2 2
    2 2 . 213 2011 2 2
    2 2 .  76 2011 2 2
    2 2 . 166 2012 2 2
    2 2 .  42 2012 2 2
    2 2 . 222 2012 2 2
    2 2 . 118 2012 2 2
    2 2 .  98 2012 2 2
    2 2 .  92 2012 2 2
    2 2 .  78 2012 2 2
    2 2 . 221 2012 2 2
    2 2 . 213 2012 2 2
    2 2 . 162 2012 2 2
    2 2 .  76 2012 2 2
    2 2 .   . 2012 2 2
    2 2 .  49 2013 2 2
    2 2 . 214 2013 2 2
    2 2 . 185 2013 2 2
    2 2 .  97 2013 2 2
    2 2 .  42 2013 2 2
    2 2 .  98 2013 2 2
    2 2 . 222 2013 2 2
    2 2 . 162 2013 2 2
    2 2 . 213 2013 2 2
    2 2 .  52 2013 2 2
    2 2 . 221 2013 2 2
    2 2 .  31 2013 2 2
    2 2 .  92 2013 2 2
    2 2 .  14 2013 2 2
    2 2 .  36 2013 2 2
    2 2 .   . 2013 2 2
    2 2 .  76 2013 2 2
    2 2 .  78 2013 2 2
    2 2 . 118 2013 2 2
    2 2 . 170 2013 2 2
    2 2 . 166 2013 2 2
    2 2 .  97 2014 2 2
    2 2 . 170 2014 2 2
    2 2 .  31 2014 2 2
    2 2 .  52 2014 2 2
    2 2 . 221 2014 2 2
    2 2 . 185 2014 2 2
    2 2 .  49 2014 2 2
    2 2 . 213 2014 2 2
    end
    label values Impl_Jur Impl_Jur
    label def Impl_Jur 1 "Afghanistan", modify
    label def Impl_Jur 2 "Albania", modify
    label values Aff_Jur Aff_Jur
    label def Aff_Jur 14 "Azerbaijan", modify
    label def Aff_Jur 31 "Bulgaria", modify
    label def Aff_Jur 36 "Canada", modify
    label def Aff_Jur 42 "China", modify
    label def Aff_Jur 49 "Croatia", modify
    label def Aff_Jur 52 "Czechia", modify
    label def Aff_Jur 76 "Germany", modify
    label def Aff_Jur 78 "Greece", modify
    label def Aff_Jur 92 "India", modify
    label def Aff_Jur 97 "Israel", modify
    label def Aff_Jur 98 "Italy", modify
    label def Aff_Jur 118 "Macedonia", modify
    label def Aff_Jur 148 "Nigeria", modify
    label def Aff_Jur 154 "Pakistan", modify
    label def Aff_Jur 162 "Poland", modify
    label def Aff_Jur 166 "Republic of Korea", modify
    label def Aff_Jur 170 "Russia", modify
    label def Aff_Jur 185 "Serbia", modify
    label def Aff_Jur 213 "Turkey", modify
    label def Aff_Jur 214 "Turkmenistan", modify
    label def Aff_Jur 221 "United Kingdom", modify
    label def Aff_Jur 222 "United States of America", modify
    label values country country
    label def country 1 "Afghanistan", modify
    label def country 2 "Albania", modify














  • #2
    multencode from SSC ensures that two or more variables are encoded consistently.

    Comment


    • #3
      Dear Mr.Cox,

      Thank you for your response. I didn't know about this command. However, my problem is not encoding the variable. I have a string variable "Implementing Jurisdiction" which is basically the name of the country that implements a policy. Using the following lines, I encode them and assign them a number as ID:


      encode ImplementingJurisdiction, gen(country)
      egen countryid= group(country)


      which is simply numbers from 1 to 180, the number of countries ordered alphabetically.

      now the problem is, I would like to have associated number(ID) always to in the column beside the country no matter if it is in the that implemented the policy or affected by the policy.
      Implement_country_ID Implement_country policy Affected_country_ID Affected_country
      1 Italy Tariff_measure 2 Germany
      1 Italy Tariff_measure 3 England
      2 Germany Tariff_measure 1 Italy
      2 Germany Anti_dumping 3 England
      3 England Anti_dumping 1 Italy
      3 England Tariff_measure 1 Italy
      3 England Tariff_measure 2 Germany
      In this example when I assign 1 to Italy; whenever I have Italy, its ID must be 1, no matter if Italy is implementing a policy or is affected by a policy that some other countries take. I do not know how to keep the "Affected_country_ID" column consistent with "Implement_country_ID" column.

      Comment


      • #4
        If I follow you correctly, that is, again, precisely what multencode will ensure.

        Comment


        • #5
          Thank you. True, it worked. I was confused about how to recover the numbers (IDs) beside them. I just removed the labels and I also have the numerical ID.

          Comment

          Working...
          X