Announcement

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

  • Stata not recognizing variable for merging

    Hello
    I am learning how to merge datasets. I have two datsets forex and gdp. I tried using the merge option but I get the error below. I dont understand why Stata cannot find the 'frex' variable in forex.dta. What am I doing wrong?

    . merge 1:1 frex using "C:\Users\chief\Desktop\dataset\covariates\gdp.dta "
    variable frex not found
    r(111);

    . dataex

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str55 country float year double frex str25 NAMES_STD
    "Equatorial Guinea"     1995                  0 "equatorial guinea"    
    "Luxembourg"            2000                 .1 "luxembourg"           
    "Congo-Brazzaville"     1998                 .1 "congobrazzaville"     
    "Luxembourg"            2001                 .1 "luxembourg"           
    "Luxembourg"            2002                 .2 "luxembourg"           
    "Liberia"               2000                 .2 "liberia"              
    "Cameroon"              1997                 .3 "cameroon"             
    "Luxembourg"            1999                 .3 "luxembourg"           
    "Liberia"               1996                 .3 "liberia"              
    "Liberia"               1997                 .4 "liberia"              
    "Liberia"               2001                 .4 "liberia"              
    "Liberia"               1999                 .4 "liberia"              
    "Equatorial Guinea"     1996                 .5 "equatorial guinea"    
    "Liberia"               1998                 .6 "liberia"              
    "Cameroon"              1998                 .6 "cameroon"             
    "Equatorial Guinea"     1998                 .8 "equatorial guinea"    
    "Cameroon"              1999                1.1 "cameroon"             
    "Cameroon"              1996                2.1 "cameroon"             
    "Cameroon"              1995                3.2 "cameroon"             
    "Liberia"               2002                3.3 "liberia"              
    "Ireland"               2012                3.3 "ireland"              
    "Equatorial Guinea"     1999                3.4 "equatorial guinea"    
    "Chad"                  2017                3.9 "chad"                 
    "Chad"                  2016                  4 "chad"                 
    "Ireland"               2013                4.2 "ireland"              
    "Equatorial Guinea"     1997                4.9 "equatorial guinea"    
    "Sao Tomé e Príncipe" 1996                  5 "sao tomé e príncipe"
    "Equatorial Guinea"     2019  5.099999904632568 "equatorial guinea"    
    "Sao Tomé e Príncipe" 1995                5.1 "sao tomé e príncipe"
    "Liberia"               2003                7.3 "liberia"              
    "Cabo Verde"            1998                8.3 "cabo verde"           
    "Equatorial Guinea"     2017                8.4 "equatorial guinea"    
    "Equatorial Guinea"     2021  8.699999809265137 "equatorial guinea"    
    "Gabon"                 2001                9.6 "gabon"                
    "Sao Tomé e Príncipe" 1998                9.7 "sao tomé e príncipe"
    "Sao Tomé e Príncipe" 1999               10.9 "sao tomé e príncipe"
    "Sao Tomé e Príncipe" 2000               11.6 "sao tomé e príncipe"
    "Luxembourg"            1998               12.1 "luxembourg"           
    "Sao Tomé e Príncipe" 1997               12.4 "sao tomé e príncipe"
    "Equatorial Guinea"     2018 12.699999809265137 "equatorial guinea"    
    "Anguilla"              1995               12.8 "anguilla"             
    "Anguilla"              1996               14.4 "anguilla"             
    "Solomon Islands"       1995               15.1 "solomon islands"      
    "Gabon"                 1998               15.3 "gabon"                
    "Sao Tomé e Príncipe" 2001               15.5 "sao tomé e príncipe"
    "Anguilla"              1997               16.3 "anguilla"             
    "Burundi"               2001               17.2 "burundi"              
    "Slovakia"              2012               17.2 "slovakia"             
    "Sao Tomé e Príncipe" 2002               17.3 "sao tomé e príncipe"
    "Solomon Islands"       2001               17.4 "solomon islands"      
    "Sierra Leone"          1995               17.5 "sierra leone"         
    "Gabon"                 1999               17.8 "gabon"                
    "Solomon Islands"       2002               17.9 "solomon islands"      
    "Anguilla"              1998               18.1 "anguilla"             
    "Sierra Leone"          1999               18.6 "sierra leone"         
    "Liberia"               2004               18.7 "liberia"              
    "Sierra Leone"          1996               18.9 "sierra leone"         
    "Cabo Verde"            1997               19.3 "cabo verde"           
    "Sao Tomé e Príncipe" 2004               19.5 "sao tomé e príncipe"
    "Anguilla"              1999               19.9 "anguilla"             
    "Anguilla"              2000               20.3 "anguilla"             
    "Seychelles"            1996               20.6 "seychelles"           
    "Tonga"                 2001               21.4 "tonga"                
    "Seychelles"            1998               21.6 "seychelles"           
    "Tonga"                 1999               22.1 "tonga"                
    "Dominica"              1995               22.1 "dominica"             
    "Tonga"                 2000               22.3 "tonga"                
    "Tonga"                 2002               22.5 "tonga"                
    "Equatorial Guinea"     2000               22.9 "equatorial guinea"    
    "Dominica"              1996               22.9 "dominica"             
    "Eritrea"               1998               23.1 "eritrea"              
    "Eritrea"               2006               23.6 "eritrea"              
    "Equatorial Guinea"     2020 23.799999237060547 "equatorial guinea"    
    "Luxembourg"            1997               23.9 "luxembourg"           
    "Dominica"              1997               23.9 "dominica"             
    "Anguilla"              2001               24.2 "anguilla"             
    "Tajikistan"            1997               24.3 "tajikistan"           
    "Eritrea"               2003               24.7 "eritrea"              
    "Burundi"               2000               25.2 "burundi"              
    "Seychelles"            1997               25.2 "seychelles"           
    "Liberia"               2005               25.4 "liberia"              
    "Sao Tomé e Príncipe" 2003               25.4 "sao tomé e príncipe"
    "Eritrea"               2000               25.5 "eritrea"              
    "Tonga"                 1997               25.7 "tonga"                
    "Seychelles"            1995               25.9 "seychelles"           
    "Anguilla"              2002               26.2 "anguilla"             
    "Tonga"                 1998               26.7 "tonga"                
    "Ireland"               2011               26.7 "ireland"              
    "Sao Tomé e Príncipe" 2005               26.7 "sao tomé e príncipe"
    "Tonga"                 1995               26.9 "tonga"                
    "Mauritania"            2003               26.9 "mauritania"           
    "Suriname"              1999               27.3 "suriname"             
    "Equatorial Guinea"     2016               27.3 "equatorial guinea"    
    "Sierra Leone"          1997               27.3 "sierra leone"         
    "Cabo Verde"            1996               27.5 "cabo verde"           
    "Congo-Brazzaville"     2002               27.7 "congobrazzaville"     
    "Dominica"              1998               27.7 "dominica"             
    "Eritrea"               2005               27.9 "eritrea"              
    "Guinea"                2006                 28 "guinea"               
    "Liberia"               1995                 28 "liberia"              
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 4872 observations
    Use the count() option to list more

    . use "C:\Users\chief\Desktop\dataset\covariates\gdp.dta "

    . dataex

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str30 country float year double gdp str25 NAMES_STD
    "Afghanistan"    1995           . "afghanistan"   
    "Afghanistan"    1996           . "afghanistan"   
    "Afghanistan"    1997           . "afghanistan"   
    "Afghanistan"    1998           . "afghanistan"   
    "Afghanistan"    1999           . "afghanistan"   
    "Afghanistan"    2000           . "afghanistan"   
    "Afghanistan"    2001           . "afghanistan"   
    "Afghanistan"    2002 4.51799e+11 "afghanistan"   
    "Afghanistan"    2003 4.91703e+11 "afghanistan"   
    "Afghanistan"    2004 4.98656e+11 "afghanistan"   
    "Afghanistan"    2005 5.54654e+11 "afghanistan"   
    "Afghanistan"    2006 5.84369e+11 "afghanistan"   
    "Afghanistan"    2007 6.65165e+11 "afghanistan"   
    "Afghanistan"    2008 6.91273e+11 "afghanistan"   
    "Afghanistan"    2009  8.3914e+11 "afghanistan"   
    "Afghanistan"    2010 9.59661e+11 "afghanistan"   
    "Afghanistan"    2011 9.63753e+11 "afghanistan"   
    "Afghanistan"    2012 1.08665e+12 "afghanistan"   
    "Afghanistan"    2013 1.14751e+12 "afghanistan"   
    "Afghanistan"    2014 1.17878e+12 "afghanistan"   
    "Afghanistan"    2015 1.19589e+12 "afghanistan"   
    "Afghanistan"    2016 1.22292e+12 "afghanistan"   
    "Afghanistan"    2017 1.25529e+12 "afghanistan"   
    "Afghanistan"    2018 1.27022e+12 "afghanistan"   
    "Afghanistan"    2019  1.3199e+12 "afghanistan"   
    "Afghanistan"    2020 1.28887e+12 "afghanistan"   
    "Afghanistan"    2021 1.02207e+12 "afghanistan"   
    "Afghanistan"    2022           . "afghanistan"   
    "Albania"        1995 5.64311e+11 "albania"       
    "Albania"        1996 6.15664e+11 "albania"       
    "Albania"        1997 5.48433e+11 "albania"       
    "Albania"        1998 5.96857e+11 "albania"       
    "Albania"        1999 6.73796e+11 "albania"       
    "Albania"        2000   7.206e+11 "albania"       
    "Albania"        2001 7.80361e+11 "albania"       
    "Albania"        2002 8.15763e+11 "albania"       
    "Albania"        2003 8.60863e+11 "albania"       
    "Albania"        2004 9.08337e+11 "albania"       
    "Albania"        2005 9.58536e+11 "albania"       
    "Albania"        2006 1.01511e+12 "albania"       
    "Albania"        2007 1.07585e+12 "albania"       
    "Albania"        2008 1.15654e+12 "albania"       
    "Albania"        2009 1.19533e+12 "albania"       
    "Albania"        2010 1.23965e+12 "albania"       
    "Albania"        2011  1.2712e+12 "albania"       
    "Albania"        2012 1.28921e+12 "albania"       
    "Albania"        2013 1.30213e+12 "albania"       
    "Albania"        2014 1.32524e+12 "albania"       
    "Albania"        2015 1.35464e+12 "albania"       
    "Albania"        2016 1.39955e+12 "albania"       
    "Albania"        2017 1.45277e+12 "albania"       
    "Albania"        2018 1.51116e+12 "albania"       
    "Albania"        2019 1.54271e+12 "albania"       
    "Albania"        2020 1.49177e+12 "albania"       
    "Albania"        2021 1.62466e+12 "albania"       
    "Albania"        2022 1.70336e+12 "albania"       
    "Algeria"        1995 8.80813e+12 "algeria"       
    "Algeria"        1996 9.16926e+12 "algeria"       
    "Algeria"        1997 9.27012e+12 "algeria"       
    "Algeria"        1998  9.7429e+12 "algeria"       
    "Algeria"        1999 1.00547e+13 "algeria"       
    "Algeria"        2000 1.04367e+13 "algeria"       
    "Algeria"        2001 1.07499e+13 "algeria"       
    "Algeria"        2002 1.13518e+13 "algeria"       
    "Algeria"        2003 1.21692e+13 "algeria"       
    "Algeria"        2004 1.26924e+13 "algeria"       
    "Algeria"        2005 1.34413e+13 "algeria"       
    "Algeria"        2006 1.36698e+13 "algeria"       
    "Algeria"        2007 1.41346e+13 "algeria"       
    "Algeria"        2008 1.44738e+13 "algeria"       
    "Algeria"        2009 1.47054e+13 "algeria"       
    "Algeria"        2010 1.52348e+13 "algeria"       
    "Algeria"        2011 1.56766e+13 "algeria"       
    "Algeria"        2012 1.62096e+13 "algeria"       
    "Algeria"        2013 1.66635e+13 "algeria"       
    "Algeria"        2014 1.72967e+13 "algeria"       
    "Algeria"        2015 1.79367e+13 "algeria"       
    "Algeria"        2016 1.85106e+13 "algeria"       
    "Algeria"        2017 1.87513e+13 "algeria"       
    "Algeria"        2018 1.89763e+13 "algeria"       
    "Algeria"        2019  1.9166e+13 "algeria"       
    "Algeria"        2020 1.81886e+13 "algeria"       
    "Algeria"        2021  1.8807e+13 "algeria"       
    "Algeria"        2022   1.939e+13 "algeria"       
    "American Samoa" 1995           . "american samoa"
    "American Samoa" 1996           . "american samoa"
    "American Samoa" 1997           . "american samoa"
    "American Samoa" 1998           . "american samoa"
    "American Samoa" 1999           . "american samoa"
    "American Samoa" 2000           . "american samoa"
    "American Samoa" 2001           . "american samoa"
    "American Samoa" 2002   7.250e+08 "american samoa"
    "American Samoa" 2003   7.320e+08 "american samoa"
    "American Samoa" 2004   7.350e+08 "american samoa"
    "American Samoa" 2005   7.320e+08 "american samoa"
    "American Samoa" 2006   7.020e+08 "american samoa"
    "American Samoa" 2007   7.150e+08 "american samoa"
    "American Samoa" 2008   6.960e+08 "american samoa"
    "American Samoa" 2009   6.670e+08 "american samoa"
    "American Samoa" 2010   6.690e+08 "american samoa"
    end

  • #2
    merge is a command, not an option.

    Your second dataset has variables


    Code:
     country  year  gdp NAMES_STD
    and it's the absence of
    frex in that dataset that is the problem. That is, the variable frex must appear in both datasets. A different point is that frex doesn't look like a good variable to merge on, regardless. Good variables to merge on are identifiers, indicating entity, time or some such. country and year look suitable, but watch out, as large or even small variations in country name will undermine merging.

    Comment


    • #3

      When I try year or country, I get:

      . merge 1:1 country using "C:\Users\chief\Desktop\dataset\covariates\debt2.d ta"
      variable country does not uniquely identify observations in the master data
      r(459);

      . merge 1:1 year using "C:\Users\chief\Desktop\dataset\covariates\debt2.d ta"
      variable year does not uniquely identify observations in the master data
      r(459);

      The objective is to get country year gdp frex STD_names in one set.

      How can I achieve this?
      Thank you.

      Comment


      • #4
        I used the incorrect dataset (debt2) in the previous post. I get the same message if I used gdp.dta

        Comment


        • #5
          You need to specify both country and year. The error messages are informative. country is not a unique identifier because of multiple values of year, and conversely.

          Comment


          • #6
            Thank you Nick. It works now!

            Comment

            Working...
            X