Announcement

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

  • Dummy Variable creation

    Dear Stata Users,

    I am trying to create a dummy variable for the number of times a country has graduated from using IDA financing. The way countries graduate is if they have GNI per capita above the operating cut-off for the IDA. This various year to year.
    I want to create a dummy variable for number of times a country has achieved a GNI per capita above the operating cut-off for a specific year, For example Benin in 1996 did not have a GNI per capita large enough to graduate from using IDA financing. However my code provides me with the very different results

    The current code I'm using is gen IDAcrossing= .
    replace IDAcrossing=1 if GNI per capita>= x & year== 1996.000

    However, I keep getting the wrong results does anyone have any suggestions?

    Kind Regards
    Farai

  • #2
    You are more likely to get a helpful response if you show example data using the -dataex- command and if you show how you know what the cutoff in each year is (if it isn't just a variable in your data set.)

    If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hi Clyde,

      Thank you for the clarification, hopefully my message below is much more clearer. As mentioned in my first message I am having problems creating a dummy variable and this is my code. The code is not providing me with an exact matching.


      Code:
      gen idacrossing = .
      Code:
      replace idacrossing = 1 if GNIPerCapita<925 & Year == 1996.0000

      Code for my dataex

      Code:
      dataex Country GNIpercapita Year
      clear
      input str24 Country str17 GNIpercapita int Year
      "Afghanistan" ".." 1996
      "Afghanistan" ".." 1996
      "Afghanistan" ".." 1996
      "Afghanistan" ".." 1996
      "Afghanistan" ".." 1996
      "Afghanistan" ".." 1996
      "Afghanistan" "" 1996
      "Angola" ".." 1996
      "Angola" ".." 1996
      "Angola" ".." 1996
      "Angola" ".." 1996
      "Angola" ".." 1996
      "Angola" ".." 1996
      "Angola" "" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "602.4328062796428" 1996
      "Bangladesh" "" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "816.739703773182" 1996
      "Benin" "" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "864.9446225682042" 1996
      "Bhutan" "" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "395.469337036763" 1996
      "Burkina Faso" "" 1996
      "Burundi" ".." 1996
      "Burundi" ".." 1996
      "Burundi" ".." 1996
      "Burundi" ".." 1996
      "Burundi" ".." 1996
      "Burundi" ".." 1996
      "Burundi" "" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "391.6569197516162" 1996
      "Cambodia" "" 1996
      "Central African Republic" ".." 1996
      "Central African Republic" ".." 1996
      "Central African Republic" ".." 1996
      "Central African Republic" ".." 1996
      "Central African Republic" ".." 1996
      "Central African Republic" ".." 1996
      "Central African Republic" "" 1996
      "Chad" ".." 1996
      "Chad" ".." 1996
      "Chad" ".." 1996
      "Chad" ".." 1996
      "Chad" ".." 1996
      "Chad" ".." 1996
      "Chad" "" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "1110.102525088359" 1996
      "Comoros" "" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "444.7925808553353" 1996
      "Congo, Dem. Rep." "" 1996
      "Djibouti" ".." 1996
      "Djibouti" ".." 1996
      "Djibouti" ".." 1996
      "Djibouti" ".." 1996
      "Djibouti" ".." 1996
      "Djibouti" ".." 1996
      "Djibouti" "" 1996
      "Eritrea" ".." 1996
      "Eritrea" ".." 1996
      "Eritrea" ".." 1996
      "Eritrea" ".." 1996
      "Eritrea" ".." 1996
      "Eritrea" ".." 1996
      "Eritrea" "" 1996
      "Ethiopia" ".." 1996
      "Ethiopia" ".." 1996
      end
      [/CODE]




      Comment


      • #4
        Hi,

        is it possible to aggregate this potential dummy variable and use it as an IV?

        Kind Regards
        Farai



        Last edited by Farai Matanga; 16 Sep 2022, 02:46.

        Comment


        • #5
          To do anything useful with your GNI pc variable, you need to destring it first

          Code:
          destring GNIPerCapita, replace
          although that might reveal problems, which explain why it is string at all.

          Now see https://www.stata-journal.com/articl...article=dm0099 for general advice on indicator variables to appreciate that

          Code:
          gen idacrossing = GNIPerCapita < 925 & Year == 1996
          would create a (0, 1) indicator variable, which as Clyde Schechter often emphasises here, is much more useful than a (1, .) variable. Further

          Code:
          gen idacrossing = GNIPerCapita < 925 & Year == 1996  if !missing(GNIPerCapita, Year)
          might be better still.

          On #4 I imagine the answer is yes if IV means independent variable but I have no idea if IV means instrumental variable. In either case how to do it depends on what kind of aggregation you have in mind.

          Comment


          • #6
            Thank you Nick by IV, I mean instrumental variable. I would like to aggregate all the idacrossing across my panel dataset which runs from 1996-2019.

            Kind Regards
            Farai

            Comment


            • #7
              Thanks for the further information. It takes an econometrician to advise on instrumental variables, and I don't qualify.

              Comment


              • #8
                Farai Matanga it is impossible to even begin thinking about your IV question without having some information about your estimation model and the endogenous variable which are you trying to use this to instrument for.

                Comment


                • #9
                  Thanks again Nick,

                  Just I have one more question, suppose I want to use the
                  Code:
                  gen idacrossing = GNIPerCapita < 925 & Year == 1996  if !missing(GNIPerCapita, Year)
                  For different years in my data should the code be

                  Code:
                  gen idacrossing = GNIPerCapita < 925 & Year == 1997  if !missing(GNIPerCapita, Year)
                  Code:
                  gen idacrossing = GNIPerCapita < 895 & Year == 1998  if !missing(GNIPerCapita, Year)

                  Comment


                  • #10
                    Hemanshu Kumar I am looking at the relationship between foreign aid and FDI flows between Donor and Recipient countries, the endogeneity problems come with Aid variable so the IDA crossing is instrumenting for Aid.

                    Comment


                    • #11
                      #9,Do you want three variables or one? If three variables, use different variable names.

                      Comment


                      • #12
                        Hi Nick ideally I would like two when the country has crossed the IDA crossing and when it hasn't

                        Here is the code I applied but I got the error no observations
                        Code:
                        gen idacrossing = GNIPercapita > 925 & Year == 1996  if!missing(GNIPercapita, Year)
                        Code:
                        ivregress 2sls FDIflows (NetODA =idacrossing) AnnualGDPpercapitaDonorCo AnnualGDPpercapitaRecipie InternetAccess TradeValueExports TradeValueExportsRecipient, first

                        Comment

                        Working...
                        X