Announcement

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

  • How can I create "Country Dummy" automatically?

    Dear all,
    Currently I am using 178 countries in my data set and I would like to use country fixed effect.

    Now, dummy creation for each countries is as follow;

    gen DAFG=0
    replace DAFG=1 if iso3i=="AFG" | iso3j=="AFG"
    gen DAGO=0
    replace DAGO=1 if iso3i=="AGO" | iso3j=="AGO"
    ..................................................

    .................................................. ...........

    .................................................. ................
    gen DVNM=0
    replace DVNM=1 if iso3i=="VNM" | iso3j=="VNM"
    gen DYEM=0
    replace DYEM=1 if iso3i=="YEM" | iso3j=="YEM"
    gen DZAF=0
    replace DZAF=1 if iso3i=="ZAF" | iso3j=="ZAF"
    gen DZMB=0
    replace DZMB=1 if iso3i=="ZMB" | iso3j=="ZMB"
    gen DZWE=0
    replace DZWE=1 if iso3i=="ZWE" | iso3j=="ZWE"

    The above command are manual command and please let me know automatically command to create 178 countries dummy.

    Thank you very much.
    Myo


  • #2
    Welcome to the Stata Forum / Statalist,

    Please read the FAQ. There you’ll find information about sharing data/command/output.

    You may create these binary variables just by typing;

    Code:
    tabulate country, gen(mydummy)
    That being said, maybe you don’t even need to do it.
    Best regards,

    Marcos

    Comment


    • #3
      Creating 178 dummy variables is probably not what you want.
      Try for example, the below, with an option to do a fixed effect regression through xtreg, or by including dummies for all you countries with regress.
      This does require that your country id variable is numeric; see help file of group for this purpose
      Code:
      webuse grunfeld
      reg invest mvalue i.company
      xtreg invest mvalue, fe

      Comment


      • #4
        Myo:
        I do share previous comments.
        As an aside, if you want to go -xt-, please note that the (highly) recommended layout is -long- (not -wide-, that is the one that your dataset in all likelihood adopts).
        At the top of that, 178 dummies in -wide- format can hit (and probably overcome) -maxvar- limits and eat too many degrees of freedom.
        See -help reshape- to change the layout of your dataset from -wide- to -long-..
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Thank you very much for suggestions and all comments.

          Thank you very much for your code @ Marcos. I can use like that;

          tabulate iso3i, gen (A)

          and then
          A1 to A173 variables appear, and then I have to continue
          tabulate iso3j, gen(B)
          B1 to B173 variables define after above command.

          I would like to create
          C1= A1 & B1
          C2= A2 & B2
          ....................................
          ....................................
          ...................................
          C171= A171 & B171
          C172= A172 & B172
          C173= A173 & B173

          How should I create C1 to C173 because I have two columns for countries, iso3i and iso3j.
          Last edited by Myo Win; 11 Jun 2018, 05:26.

          Comment


          • #6
            As I said, I think that: a) you probably don't need to create so many binary variables; b) to create these variables, just a single line of command would do (as I posted); c) Anyway, I fail to see the point of doing so. Perhaps you could explain why you should do it.

            To end, maybe you just need to use the country variable as a cluster in the regression analysis. Hopefully that helps.
            Best regards,

            Marcos

            Comment


            • #7
              Why do you currently have two country name variables? Do they contain different info, or do the two lists have missing observations sometimes?
              If it is the latter, do e.g.;
              Code:
              gen countrycode=iso3i
              replace countrycode=iso3j if iso3i==""
              If this is not what you want, explain the reason why you have two country code variables and what the result is that you want.

              Comment


              • #8
                Dear Jorrit,
                Thank you very much for your code and command. I would to use trade data and iso3i is export from country(I) to country (j) and iso3j is export from country j to country I. I want to measure FTA impact trade flow and want to use country fixed effect. Please check the following variables. I also agree creating 173 dummy variables is overcome. When I search the previous post I saw the following link;
                https://www.statalist.org/forums/for...-fixed-effects
                gen DAFG=0
                replace DAFG=1 if iso3i=="AFG" | iso3j=="AFG"
                gen DAGO=0
                replace DAGO=1 if iso3i=="AGO" | iso3j=="AGO"
                The above command are manual command and it can be wrong calculation. Please check iso3i and iso3j data as following;

                iso3i iso3j DAFG DAGO DALB DVNE DZWE
                EST AFG 1 0 0 0 0
                PAN AFG 1 0 0 0 0
                TJK AFG 1 0 0 0 0
                LSO AFG 1 0 0 0 0
                IRL AFG 1 0 0 0 0
                FIN AFG 1 0 0 0 0
                PHL AFG 1 0 0 0 0
                PRK AFG 1 0 0 0 0
                LBR AFG 1 0 0 0 0
                BEL AFG 1 0 0 0 0
                ALB AFG 1 0 0 0 0
                QAT AFG 1 0 0 0 0
                MYS AFG 1 0 0 0 0
                USA AFG 1 0 0 0 0
                DEU AFG 1 0 0 0 0
                SEN AFG 1 0 0 0 0
                LBY AFG 1 0 0 0 0
                ECU AFG 1 0 0 0 0
                SUR AFG 1 0 0 0 0
                ZWE AFG 1 0 0 0 0
                GNB AFG 1 0 0 0 0
                VCT AFG 1 0 0 0 0
                NER AFG 1 0 0 0 0
                BRN AFG 1 0 0 0 0
                AUS AGO 0 1 0 0 0
                EST AGO 0 1 0 0 0
                BWA AGO 0 1 0 0 0
                GNQ AGO 0 1 0 0 0
                DNK AGO 0 1 0 0 0
                MNE AGO 0 1 0 0 0
                ARG AGO 0 1 0 0 0
                HKG AGO 0 1 0 0 0
                BDI AGO 0 1 0 0 0
                SGP AGO 0 1 0 0 0
                LBY AGO 0 1 0 0 0
                KWT AGO 0 1 0 0 0
                MMR AGO 0 1 0 0 0
                TZA AGO 0 1 0 0 0
                CHE AGO 0 1 0 0 0
                THA AGO 0 1 0 0 0
                GTM AGO 0 1 0 0 0
                GRD AGO 0 1 0 0 0
                MWI AGO 0 1 0 0 0
                JAM AGO 0 1 0 0 0
                BEN AGO 0 1 0 0 0
                URY AGO 0 1 0 0 0
                AFG AGO 1 1 0 0 0
                ISL AGO 0 1 0 0 0
                UGA AGO 0 1 0 0 0
                BGD AGO 0 1 0 0 0
                YEM AGO 0 1 0 0 0
                BLR AGO 0 1 0 0 0
                JOR AGO 0 1 0 0 0
                LKA AGO 0 1 0 0 0
                UZB AGO 0 1 0 0 0
                HRV AGO 0 1 0 0 0
                DZA AGO 0 1 0 0 0
                MOZ AGO 0 1 0 0 0
                MDG AGO 0 1 0 0 0
                SWE AGO 0 1 0 0 0
                SVN AGO 0 1 0 0 0
                MEX AGO 0 1 0 0 0
                BEL AGO 0 1 0 0 0
                TLS AGO 0 1 0 0 0
                BLZ AGO 0 1 0 0 0
                KEN AGO 0 1 0 0 0
                ZAF AGO 0 1 0 0 0
                GIN AGO 0 1 0 0 0
                DEU AGO 0 1 0 0 0
                COG AGO 0 0 1 0 0
                ATG AGO 0 0 1 0 0
                MDA AGO 0 0 1 0 0
                ALB AGO 0 0 1 0 0
                PER AGO 0 0 1 0 0
                SAU AGO 0 0 1 0 0
                AGO AGO 0 0 1 0 0
                CIV AGO 0 0 1 0 0
                AZE AGO 0 0 1 0 0
                TUN AGO 0 0 0 1 0
                LVA AGO 0 0 0 1 0
                GMB AGO 0 0 0 1 0
                LCA AGO 0 0 0 1 0
                CYP AGO 0 0 0 1 0
                NIC AGO 0 0 0 1 0
                BGR AGO 0 0 0 1 0
                MUS AGO 0 0 0 0 1
                NPL AGO 0 0 1 0 1
                NAM AGO 0 0 1 0 1
                VNM AGO 0 0 1 0 1
                EST AGO 0 0 1 0 1
                SWZ AGO 0 0 1 0 1
                SLV AGO 0 0 1 0 1
                ROU AGO 0 0 1 0 1

                Comment


                • #9
                  I am using following command for country fixed effect;
                  reg N_TF TA $xlist DAGO-DZWE if year==1990, robust
                  reg N_TF TA $xlist DAGO-DZWE if year==1995, robust
                  reg N_TF TA $xlist DAGO-DZWE if year==2000 robust


                  DAGO to DZWE will be 173 dummy variables. Actually i don't want to use above command for country fixed effect.

                  Comment


                  • #10
                    If you don’t want to use the cornucopia of dummies, and considering the advice from this forum was against doing so, we reached an agreement. However, if you just want a friendlier command to create the dummies, fine, it was already given. This notwithstanding, the humoungous output seems to be something impossible to get rid of, considering the sort of analysis you chose.
                    Best regards,

                    Marcos

                    Comment

                    Working...
                    X