Announcement

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

  • Creating neighbor information variables in country panel data

    Hi everyone,

    for my panel data set that's unit of analysis is countries, I am trying to create variables that describe information of contiguous countries. I.e., I want a variable that indicates the average GDP of each of the countries' contiguous neighbors. As an example, speaking for an individual observation, i want the variable to show: what is the average GDP of all of Germany's neighboring countries in year 2000? How do I create this variable?

    I was adviced to look at spatial lagging but as far as I have understood, the concept of spatial lags uses longitudes and latitudes and then sets a threshold as of with which distance, a country is considered a neighbor. As I only care about contiguous neighbors though, I don't see how spatial lagging would help me here.

    I would be very happy about some advice. Thank you in advance!

  • #2
    To do this, you need, in addition to the data set you mention, two other data sets:

    1. A data set of pairs of continguous countries.
    2. A data set that gives the GDP of each country in year 2000.

    Since the code to put all of this together depends on how those data sets look, it would be best if you post back showing examples from these two data sets, as well as an example of your original datas et. Do that by using the -dataex- command. (If you don't have the -dataex- command installed, run -ssc install dataex- and then run -help dataex- to read the instructions for using it.)

    Comment


    • #3
      Thanks for the reply Clyde,

      how would the build up of the dataset of pairs of contiguous countries have to look like? And as my Germany example was just meant to clearify things but I need the information for all of my observations, how would I avoid doubling information? Obviously Germany is a neighbor of Austria but when I look at the observations of Austria I will have the information that Germany is a neighbor of Austria as well.

      Comment


      • #4
        You don't have to worry about that. In fact, merging the information with the other files will be easier if you have both Germany Austria and Austria Germany in the data set. But it can also be made to work if you only have these pairings in one direction. Let's see what you have, and we'll figure out how to work with it.

        Comment


        • #5
          Here's one way to generate a list of country pairs that share a common boundary. The idea is to use a shapefile that describes the boundaries of each country and determine conterminous countries using common boundary points. For those not familiar with shapefiles, they need to be converted to Stata datasets using the shp2dta user-written program available from SSC. The database dataset contains one observation per country with information about the country name, region, ISO code, etc. The coordinates dataset contains one observation per polygon point. The _Y variable is the latitude, the _X variable is the longitude. Once connected (in the order they appear), these points form a polygon that represents the country's boundary. Both datasets have a common _ID variable to connect the country-level data to the polygon points.

          Code:
          * shapefile of the world's country boundaries found at
          * http://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-admin-0-countries/
          * (click on the "Download without boundary lakes")
          
          * to install, type: ssc install shp2dta
          shp2dta using "ne_110m_admin_0_countries_lakes/ne_110m_admin_0_countries_lakes.shp", ///
              genid(_ID) data("world_data.dta") coor("world_coor.dta") replace
          
          * conterminous countries share one or more common boundary points. Most shared
          * boundary points are between two countries; a few connect 3 countries; one
          * connects 4 countries.
          use "world_coor.dta", clear
          
          * remove duplicates within countries and missing coordinates which
          * indicate the start of a new polygon
          bysort _Y _X _ID: keep if _n == 1 & !mi(_Y,_X)
          
          * reduce to coordinates that appear in more than one country
          by _Y _X: keep if _N > 1
          
          * switch to wide form and reduce to one obs per conterminous country set
          by _Y _X: gen j = _n
          reshape wide _ID, i(_Y _X) j(j)
          keep _ID*
          bysort _ID*: keep if _n == 1
          
          * switch back to long form and form all pairwise combinations within the set
          gen set = _n
          reshape long _ID, i(set)
          drop if mi(_ID)
          drop _j
          save "country_sets.dta", replace
          rename _ID _ID_pair
          joinby set using "country_sets.dta"
          drop if _ID == _ID_pair
          
          * remove duplicates and merge with database to get the name
          bysort _ID _ID_pair: keep if _n == 1
          merge m:1 _ID using "world_data.dta", assert(match using) keep(match) ///
              keepusing(region_un iso_a3 sovereignt) nogen
              
          rename (_ID _ID_pair region_un iso_a3 sovereignt) (_ID_pair _ID region1 iso1 country1) 
          merge m:1 _ID using "world_data.dta", assert(match using) keep(match) ///
              keepusing(region_un iso_a3 sovereignt) nogen
          rename (region_un iso_a3 sovereignt) (region2 iso2 country2) 
          
          * final list
          isid iso1 iso2, sort

          Comment


          • #6
            Thank you for the help everyone.

            I couldn't work on this for some time but I am now and made some progress. I am currently working with the direct contiguity v.3.2 data from correlatesofwar.org.
            Version 3.2 of the COW Direct Contiguity data identifies all direct contiguity relationships between states in the international system from 1816 through 2016. The classification system for contiguous dyads is comprised of five categories, one for land contiguity and four for water contiguity. Land contiguity is defined as the intersection of the homeland territory of the two states in the dyad, either through a land boundary or a river (such as the Rio Grande in the case of the US-Mexico border). Water contiguity is divided into four categories, based on a separation by water of 12, 24, 150, and 400 miles.
            I am specifically working with the directed dyad-year version.

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input long dyad int state1no str3 state1ab int state2no str3 state2ab int year byte conttype float(version nstate1ab nstate2ab) str3 statenames long(state1 state2)
            365700 365 "RUS" 700 "AFG" 1991 1 3.2 0 0 "" 123 1
            700770 770 "PAK" 700 "AFG" 1959 1 3.2 0 0 "" 112 1
            700770 770 "PAK" 700 "AFG" 1969 1 3.2 0 0 "" 112 1
            700704 704 "UZB" 700 "AFG" 2008 1 3.2 0 0 "" 157 1
            700710 710 "CHN" 700 "AFG" 2000 1 3.2 0 0 ""  32 1
            630700 630 "IRN" 700 "AFG" 2000 1 3.2 0 0 ""  72 1
            700710 710 "CHN" 700 "AFG" 2015 1 3.2 0 0 ""  32 1
            700701 701 "TKM" 700 "AFG" 1996 1 3.2 0 0 "" 147 1
            365700 365 "RUS" 700 "AFG" 1976 1 3.2 0 0 "" 123 1
            700701 701 "TKM" 700 "AFG" 2010 1 3.2 0 0 "" 147 1
            700702 702 "TAJ" 700 "AFG" 2008 1 3.2 0 0 "" 144 1
            700770 770 "PAK" 700 "AFG" 1957 1 3.2 0 0 "" 112 1
            700704 704 "UZB" 700 "AFG" 2012 1 3.2 0 0 "" 157 1
            630700 630 "IRN" 700 "AFG" 1966 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1976 1 3.2 0 0 ""  72 1
            700701 701 "TKM" 700 "AFG" 1995 1 3.2 0 0 "" 147 1
            700710 710 "CHN" 700 "AFG" 1975 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1950 1 3.2 0 0 ""  32 1
            700770 770 "PAK" 700 "AFG" 1997 1 3.2 0 0 "" 112 1
            700710 710 "CHN" 700 "AFG" 1982 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1967 1 3.2 0 0 ""  32 1
            700704 704 "UZB" 700 "AFG" 2013 1 3.2 0 0 "" 157 1
            700701 701 "TKM" 700 "AFG" 2015 1 3.2 0 0 "" 147 1
            700770 770 "PAK" 700 "AFG" 1977 1 3.2 0 0 "" 112 1
            700710 710 "CHN" 700 "AFG" 1988 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1952 1 3.2 0 0 ""  32 1
            700702 702 "TAJ" 700 "AFG" 1991 1 3.2 0 0 "" 144 1
            700710 710 "CHN" 700 "AFG" 1981 1 3.2 0 0 ""  32 1
            630700 630 "IRN" 700 "AFG" 2010 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1997 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1977 1 3.2 0 0 ""  72 1
            700702 702 "TAJ" 700 "AFG" 2015 1 3.2 0 0 "" 144 1
            700704 704 "UZB" 700 "AFG" 2003 1 3.2 0 0 "" 157 1
            630700 630 "IRN" 700 "AFG" 1960 1 3.2 0 0 ""  72 1
            700770 770 "PAK" 700 "AFG" 1988 1 3.2 0 0 "" 112 1
            700704 704 "UZB" 700 "AFG" 1994 1 3.2 0 0 "" 157 1
            700702 702 "TAJ" 700 "AFG" 1995 1 3.2 0 0 "" 144 1
            700704 704 "UZB" 700 "AFG" 1996 1 3.2 0 0 "" 157 1
            700710 710 "CHN" 700 "AFG" 1964 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1987 1 3.2 0 0 ""  32 1
            700701 701 "TKM" 700 "AFG" 2005 1 3.2 0 0 "" 147 1
            365700 365 "RUS" 700 "AFG" 1990 1 3.2 0 0 "" 123 1
            700770 770 "PAK" 700 "AFG" 1981 1 3.2 0 0 "" 112 1
            700710 710 "CHN" 700 "AFG" 1953 1 3.2 0 0 ""  32 1
            700704 704 "UZB" 700 "AFG" 2005 1 3.2 0 0 "" 157 1
            700701 701 "TKM" 700 "AFG" 2000 1 3.2 0 0 "" 147 1
            700702 702 "TAJ" 700 "AFG" 2004 1 3.2 0 0 "" 144 1
            700770 770 "PAK" 700 "AFG" 2002 1 3.2 0 0 "" 112 1
            630700 630 "IRN" 700 "AFG" 1970 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1975 1 3.2 0 0 ""  72 1
            700770 770 "PAK" 700 "AFG" 1963 1 3.2 0 0 "" 112 1
            365700 365 "RUS" 700 "AFG" 1965 1 3.2 0 0 "" 123 1
            700702 702 "TAJ" 700 "AFG" 1994 1 3.2 0 0 "" 144 1
            700704 704 "UZB" 700 "AFG" 2001 1 3.2 0 0 "" 157 1
            700770 770 "PAK" 700 "AFG" 2010 1 3.2 0 0 "" 112 1
            630700 630 "IRN" 700 "AFG" 1985 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1989 1 3.2 0 0 ""  72 1
            700710 710 "CHN" 700 "AFG" 2012 1 3.2 0 0 ""  32 1
            700702 702 "TAJ" 700 "AFG" 2005 1 3.2 0 0 "" 144 1
            630700 630 "IRN" 700 "AFG" 2014 1 3.2 0 0 ""  72 1
            700770 770 "PAK" 700 "AFG" 1970 1 3.2 0 0 "" 112 1
            365700 365 "RUS" 700 "AFG" 1982 1 3.2 0 0 "" 123 1
            700710 710 "CHN" 700 "AFG" 2007 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1956 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 2002 1 3.2 0 0 ""  32 1
            700710 710 "CHN" 700 "AFG" 1983 1 3.2 0 0 ""  32 1
            700701 701 "TKM" 700 "AFG" 2008 1 3.2 0 0 "" 147 1
            700701 701 "TKM" 700 "AFG" 2013 1 3.2 0 0 "" 147 1
            700701 701 "TKM" 700 "AFG" 1991 1 3.2 0 0 "" 147 1
            365700 365 "RUS" 700 "AFG" 1953 1 3.2 0 0 "" 123 1
            700710 710 "CHN" 700 "AFG" 1998 1 3.2 0 0 ""  32 1
            700704 704 "UZB" 700 "AFG" 2000 1 3.2 0 0 "" 157 1
            365700 365 "RUS" 700 "AFG" 1956 1 3.2 0 0 "" 123 1
            630700 630 "IRN" 700 "AFG" 2011 1 3.2 0 0 ""  72 1
            700710 710 "CHN" 700 "AFG" 1958 1 3.2 0 0 ""  32 1
            700770 770 "PAK" 700 "AFG" 1984 1 3.2 0 0 "" 112 1
            700770 770 "PAK" 700 "AFG" 1985 1 3.2 0 0 "" 112 1
            700770 770 "PAK" 700 "AFG" 1996 1 3.2 0 0 "" 112 1
            700702 702 "TAJ" 700 "AFG" 2010 1 3.2 0 0 "" 144 1
            700702 702 "TAJ" 700 "AFG" 2000 1 3.2 0 0 "" 144 1
            630700 630 "IRN" 700 "AFG" 1963 1 3.2 0 0 ""  72 1
            700770 770 "PAK" 700 "AFG" 2003 1 3.2 0 0 "" 112 1
            700710 710 "CHN" 700 "AFG" 1966 1 3.2 0 0 ""  32 1
            700770 770 "PAK" 700 "AFG" 1973 1 3.2 0 0 "" 112 1
            700770 770 "PAK" 700 "AFG" 1955 1 3.2 0 0 "" 112 1
            700704 704 "UZB" 700 "AFG" 1999 1 3.2 0 0 "" 157 1
            700710 710 "CHN" 700 "AFG" 1970 1 3.2 0 0 ""  32 1
            365700 365 "RUS" 700 "AFG" 1986 1 3.2 0 0 "" 123 1
            700710 710 "CHN" 700 "AFG" 2009 1 3.2 0 0 ""  32 1
            700770 770 "PAK" 700 "AFG" 1965 1 3.2 0 0 "" 112 1
            700770 770 "PAK" 700 "AFG" 1964 1 3.2 0 0 "" 112 1
            700710 710 "CHN" 700 "AFG" 1951 1 3.2 0 0 ""  32 1
            700701 701 "TKM" 700 "AFG" 2002 1 3.2 0 0 "" 147 1
            700770 770 "PAK" 700 "AFG" 2012 1 3.2 0 0 "" 112 1
            630700 630 "IRN" 700 "AFG" 1959 1 3.2 0 0 ""  72 1
            630700 630 "IRN" 700 "AFG" 1988 1 3.2 0 0 ""  72 1
            700702 702 "TAJ" 700 "AFG" 2013 1 3.2 0 0 "" 144 1
            700710 710 "CHN" 700 "AFG" 1995 1 3.2 0 0 ""  32 1
            700770 770 "PAK" 700 "AFG" 1974 1 3.2 0 0 "" 112 1
            630700 630 "IRN" 700 "AFG" 2005 1 3.2 0 0 ""  72 1
            end
            label values state1 state1
            label def state1 32 "CHN", modify
            label def state1 72 "IRN", modify
            label def state1 112 "PAK", modify
            label def state1 123 "RUS", modify
            label def state1 144 "TAJ", modify
            label def state1 147 "TKM", modify
            label def state1 157 "UZB", modify
            label values state2 state2
            label def state2 1 "AFG", modify
            My plan was to create a matrix that has the country names in rows and colums and then code it 1/(number of neighbors) if two countries are neighbors.
            Expl: As AFG has 7 neighbors in each cell of the row "AFG" that has a neigbor in the columns, I want the value to be 1/7.
            I then want to multiply this with GDP data.

            Right now I am stuck at even coding the matrix with 1 if row and column countries are neighbors (so that I can later on divide this by a matrix that sums up the 1s of a row to get the shares). I tried to do it with a loop but it's not working properly. Aso I was thinking to code a double loop to save work. I am not sure what my mistaes are here. This is what I have done so far:

            Code:
            drop if conttype != 1 //dropping non-contiguous countries
            drop if year<1950
            drop if year>2015
            
            
            *Create neighbor matrix
            matrix neigh = J(164, 164,.) //create a 164x164 matrix because it's 164 countries
            
            **Naming matrix rows and columns after countries
            sort state1ab
            gen statenames = state1ab if nstate1ab==1 
            
            levelsof statenames, local(m)
            local nodot: subinstr local m `"."' `""', all
            mat rownames neigh = `nodot' 
            local nospace: subinstr loc nodot " " "",all
            local respace: subinstr loc nospace "'`" "'`", all 
            mat rownames neigh = `respace' 
            
            levelsof statenames, local(m)
            local nodot: subinstr local m `"."' `""', all
            mat colnames neigh = `nodot' 
            local nospace: subinstr loc nodot " " "",all
            local respace: subinstr loc nospace "'`" "'`", all 
            mat colnames neigh = `respace' 
            
            **Fill matrix with values
            sort state1ab
            enc state1ab, gen(state1)
            sort state2ab
            enc state2ab, gen(state2)
            
            local i=1
            forvalues j=1/164 {
                          sum conttype if state2==`j' & state1==1
                          mat neigh[`i',1]= r(max)
                          local i=`i'+1
            }

            Comment


            • #7
              I think your approach is unnecessarily complicated. It appears that you already have the key information you need in the variable conttype, which is 1 when the dyad consists of neighboring states, and 0 otherwise. All you need to do is, for each country, count up the number of different countries that appear in observations ("rows") where conttype == 1. Then the reciprocal of that is your weight.

              Your example data doesn't really allow a thorough exploration of the problem, because all of your observations involve a single state2 (AFG), and they all have conttype = 1. But I believe the following code will work generally. It will assign to each observation in the data a neighbor_count that gives the total number of countries that are neighbors of state2 in the data.

              Code:
              by state2 state1, sort: gen byte neighbor_count = 1 if _n == 1
              by state2: replace neighbor_count = sum(neighbor_count)
              by state2: replace neighbor_count = neighbor_count[_N]
              gen weight = 1/neighbor_count

              Comment


              • #8
                Well this does work, but I don't think it is exactly what I need. I guess I am not saying it right as I am slowly getting a little desperate over this.
                So I have a base data set:
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input int statenum str3 stateid int year double rgdppc float genconflict
                700 "AFG" 1950   892.59 0
                339 "ALB" 1950  1385.24 0
                232 "AND" 1950 65967.74 0
                160 "ARG" 1950  2173.55 0
                900 "AUL" 1950 11956.39 0
                305 "AUS" 1950  5194.43 0
                211 "BEL" 1950  7574.09 0
                760 "BHU" 1950   620.95 0
                145 "BOL" 1950  2754.81 0
                140 "BRA" 1950  1304.71 0
                355 "BUL" 1950  2284.74 0
                 20 "CAN" 1950 11485.21 0
                155 "CHL" 1950  3944.64 0
                710 "CHN" 1950   619.97 1
                100 "COL" 1950   3070.2 0
                 94 "COS" 1950  3042.58 0
                 40 "CUB" 1950  2831.36 0
                315 "CZE" 1950  4844.87 0
                390 "DEN" 1950  8879.06 0
                 42 "DOM" 1950  1539.89 0
                130 "ECU" 1950  1937.43 0
                651 "EGY" 1950   643.73 0
                530 "ETH" 1950    366.5 0
                375 "FIN" 1950  5596.16 0
                220 "FRN" 1950  6285.64 0
                265 "GDR" 1950  7263.72 0
                260 "GFR" 1950  5083.81 0
                350 "GRC" 1950   2286.3 0
                 90 "GUA" 1950  2033.68 0
                 41 "HAI" 1950  1454.43 0
                 91 "HON" 1950  1990.01 0
                310 "HUN" 1950  3431.96 0
                395 "ICE" 1950  7526.48 0
                750 "IND" 1950    811.5 1
                850 "INS" 1950  1130.61 1
                205 "IRE" 1950  4799.46 0
                630 "IRN" 1950  2380.23 0
                645 "IRQ" 1950  1887.58 0
                666 "ISR" 1950  3227.53 1
                325 "ITA" 1950  3596.14 0
                663 "JOR" 1950  2301.35 0
                740 "JPN" 1950  1764.25 0
                450 "LBR" 1950  1459.97 0
                660 "LEB" 1950  3361.38 0
                223 "LIE" 1950 39637.68 0
                212 "LUX" 1950 13063.39 0
                 70 "MEX" 1950  4174.62 0
                221 "MNC" 1950 24181.82 0
                712 "MON" 1950   601.98 0
                775 "MYA" 1950   369.96 1
                775 "MYA" 1950   369.96 1
                775 "MYA" 1950   369.96 1
                775 "MYA" 1950   369.96 1
                775 "MYA" 1950   369.96 1
                790 "NEP" 1950   686.39 0
                920 "NEW" 1950  9906.38 0
                 93 "NIC" 1950  1869.28 0
                385 "NOR" 1950 18279.87 0
                210 "NTH" 1950  8036.44 0
                698 "OMA" 1950   862.14 0
                770 "PAK" 1950  1043.51 0
                 95 "PAN" 1950  1742.67 0
                150 "PAR" 1950  2033.17 0
                135 "PER" 1950  2020.58 0
                840 "PHI" 1950  1199.19 1
                290 "POL" 1950  3386.29 0
                235 "POR" 1950  2350.15 0
                731 "PRK" 1950  1181.81 0
                732 "ROK" 1950  1181.81 0
                360 "RUM" 1950  1406.93 0
                365 "RUS" 1950  3931.53 1
                560 "SAF" 1950  3933.53 0
                 92 "SAL" 1950   376.75 0
                670 "SAU" 1950  3087.38 0
                331 "SNM" 1950 16076.92 0
                230 "SPN" 1950  3036.58 0
                780 "SRI" 1950  2084.83 0
                380 "SWD" 1950  8764.84 0
                225 "SWZ" 1950 12502.17 0
                652 "SYR" 1950   3333.7 0
                713 "TAW" 1950  1267.61 0
                711 "TBT" 1950  2255.39 0
                800 "THI" 1950   970.73 0
                640 "TUR" 1950  2728.94 0
                200 "UKG" 1950     9130 0
                165 "URU" 1950  5442.95 0
                  2 "USA" 1950 12776.54 0
                101 "VEN" 1950 10138.66 0
                678 "YEM" 1950  1260.69 0
                345 "YUG" 1950  1976.14 0
                700 "AFG" 1951   903.66 0
                339 "ALB" 1951  1446.13 0
                232 "AND" 1951    74500 0
                160 "ARG" 1951  2184.75 0
                900 "AUL" 1951 11220.23 0
                305 "AUS" 1951  5472.56 0
                211 "BEL" 1951  7913.39 0
                760 "BHU" 1951   615.27 0
                145 "BOL" 1951  2913.73 0
                140 "BRA" 1951  1308.82 0
                end
                For this dataset I want to create a variable that gives me the average rgdppc (Real GDP per capita) for all its neighboring countries in a given year, e.g. for the USA in 1950 I need the average of Canada's and Mexico's rgdppc in 1950. Because this dataset doesn't provide information on contiguity, I have my other dataset that contains all country dyads starting in 1950." conttype" used to define the type of contiguity (water land etc.) but I dropped all observations that were no contiguous neighbors which is why conttype==1 in all observtions:
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input long dyad int state1no str3 state1ab int state2no str3 state2ab int year byte conttype float(version nstate1ab nstate2ab) str3 statenames long(state1 state2) byte neighbor_count float weight
                350640 350 "GRC" 640 "TUR" 1950 1 3.2 0 0 ""     61 150 11   .0909091
                365630 630 "IRN" 365 "RUS" 1950 1 3.2 0 0 ""     72 123 20        .05
                630645 645 "IRQ" 630 "IRN" 1950 1 3.2 0 0 ""     73  72  8       .125
                339345 345 "YUG" 339 "ALB" 1950 1 3.2 0 0 ""    162   2  5         .2
                290315 315 "CZE" 290 "POL" 1950 1 3.2 0 0 ""     38 117  9  .11111111
                651666 666 "ISR" 651 "EGY" 1950 1 3.2 0 0 ""     74  46  7  .14285715
                380385 385 "NOR" 380 "SWD" 1950 1 3.2 0 0 ""    109 141  3   .3333333
                365375 375 "FIN" 365 "RUS" 1950 1 3.2 0 0 ""     52 123 20        .05
                652666 652 "SYR" 666 "ISR" 1950 1 3.2 0 0 ""    143  74  4        .25
                339345 339 "ALB" 345 "YUG" 1950 1 3.2 0 0 ""      2 162 12  .08333334
                630700 700 "AFG" 630 "IRN" 1950 1 3.2 0 0 ""      1  72  8       .125
                212220 220 "FRN" 212 "LUX" 1950 1 3.2 0 0 ""     53  90  4        .25
                 90091  91 "HON"  90 "GUA" 1950 1 3.2 0 0 ""     67  63  4        .25
                710775 710 "CHN" 775 "MYA" 1950 1 3.2 0 0 ""     32 102  6  .16666667
                 41042  41 "HAI"  42 "DOM" 1950 1 3.2 0 0 ""     66  42  1          1
                220225 225 "SWZ" 220 "FRN" 1950 1 3.2 0 0 ""    142  53  9  .11111111
                652660 652 "SYR" 660 "LEB" 1950 1 3.2 0 0 ""    143  85  3   .3333333
                652666 666 "ISR" 652 "SYR" 1950 1 3.2 1 0 "ISR"  74 143  5         .2
                710775 775 "MYA" 710 "CHN" 1950 1 3.2 0 0 ""    102  32 14 .071428575
                640652 640 "TUR" 652 "SYR" 1950 1 3.2 0 0 ""    150 143  5         .2
                  2070   2 "USA"  70 "MEX" 1950 1 3.2 0 0 ""    156  95  3   .3333333
                365712 365 "RUS" 712 "MON" 1950 1 3.2 0 0 ""    123 100  2         .5
                130135 130 "ECU" 135 "PER" 1950 1 3.2 0 0 ""     45 115  5         .2
                135155 155 "CHL" 135 "PER" 1950 1 3.2 0 0 ""     31 115  5         .2
                710790 790 "NEP" 710 "CHN" 1950 1 3.2 0 0 ""    105  32 14 .071428575
                220225 220 "FRN" 225 "SWZ" 1950 1 3.2 0 0 ""     53 142  6  .16666667
                365700 365 "RUS" 700 "AFG" 1950 1 3.2 0 0 ""    123   1  7  .14285715
                645652 645 "IRQ" 652 "SYR" 1950 1 3.2 0 0 ""     73 143  5         .2
                220230 220 "FRN" 230 "SPN" 1950 1 3.2 0 0 ""     53 136  4        .25
                355360 355 "BUL" 360 "ROM" 1950 1 3.2 0 0 ""     24 122  6  .16666667
                360365 365 "RUS" 360 "ROM" 1950 1 3.2 0 0 ""    123 122  6  .16666667
                360365 360 "ROM" 365 "RUS" 1950 1 3.2 0 0 ""    122 123 20        .05
                100135 100 "COL" 135 "PER" 1950 1 3.2 0 0 ""     33 115  5         .2
                375380 380 "SWD" 375 "FIN" 1950 1 3.2 0 0 ""    141  52  3   .3333333
                140150 140 "BRA" 150 "PAR" 1950 1 3.2 0 0 ""     21 114  3   .3333333
                220325 220 "FRN" 325 "ITA" 1950 1 3.2 0 0 ""     53  75  6  .16666667
                 91092  92 "SAL"  91 "HON" 1950 1 3.2 0 0 ""    127  67  3   .3333333
                 91093  93 "NIC"  91 "HON" 1950 1 3.2 0 0 ""    106  67  3   .3333333
                225325 325 "ITA" 225 "SWZ" 1950 1 3.2 0 0 ""     75 142  6  .16666667
                150160 160 "ARG" 150 "PAR" 1950 1 3.2 0 0 ""      6 114  3   .3333333
                150160 150 "PAR" 160 "ARG" 1950 1 3.2 0 0 ""    114   6  5         .2
                365731 731 "PRK" 365 "RUS" 1950 1 3.2 0 0 ""    119 123 20        .05
                652663 663 "JOR" 652 "SYR" 1950 1 3.2 0 0 ""     76 143  5         .2
                135155 135 "PER" 155 "CHL" 1950 1 3.2 0 0 ""    115  31  3   .3333333
                365630 365 "RUS" 630 "IRN" 1950 1 3.2 0 0 ""    123  72  8       .125
                 90092  92 "SAL"  90 "GUA" 1950 1 3.2 0 0 ""    127  63  4        .25
                630640 640 "TUR" 630 "IRN" 1950 1 3.2 0 0 ""    150  72  8       .125
                660666 660 "LEB" 666 "ISR" 1950 1 3.2 0 0 ""     85  74  4        .25
                100101 100 "COL" 101 "VEN" 1950 1 3.2 0 0 ""     33 158  3   .3333333
                212220 212 "LUX" 220 "FRN" 1950 1 3.2 0 0 ""     90  53  9  .11111111
                310360 310 "HUN" 360 "ROM" 1950 1 3.2 0 0 ""     68 122  6  .16666667
                310360 360 "ROM" 310 "HUN" 1950 1 3.2 0 0 ""    122  68  9  .11111111
                355640 355 "BUL" 640 "TUR" 1950 1 3.2 0 0 ""     24 150 11   .0909091
                140165 165 "URU" 140 "BRA" 1950 1 3.2 0 0 ""    155  21  9  .11111111
                 94095  95 "PAN"  94 "COS" 1950 1 3.2 0 0 ""    113  35  2         .5
                315365 315 "CZE" 365 "RUS" 1950 1 3.2 0 0 ""     38 123 20        .05
                100140 140 "BRA" 100 "COL" 1950 1 3.2 0 0 ""     21  33  5         .2
                731732 731 "PRK" 732 "ROK" 1950 1 3.2 0 0 ""    119 121  1          1
                145150 145 "BOL" 150 "PAR" 1950 1 3.2 0 0 ""     18 114  3   .3333333
                290365 365 "RUS" 290 "POL" 1950 1 3.2 0 0 ""    123 117  9  .11111111
                640652 652 "SYR" 640 "TUR" 1950 1 3.2 0 0 ""    143 150 11   .0909091
                 41042  42 "DOM"  41 "HAI" 1950 1 3.2 0 1 ""     42  66  1          1
                325345 345 "YUG" 325 "ITA" 1950 1 3.2 0 0 ""    162  75  6  .16666667
                645663 645 "IRQ" 663 "JOR" 1950 1 3.2 0 0 ""     73  76  5         .2
                290315 290 "POL" 315 "CZE" 1950 1 3.2 0 0 ""    117  38  8       .125
                750790 790 "NEP" 750 "IND" 1950 1 3.2 0 0 ""    105  69  6  .16666667
                155160 155 "CHL" 160 "ARG" 1950 1 3.2 0 0 ""     31   6  5         .2
                345360 345 "YUG" 360 "ROM" 1950 1 3.2 0 0 ""    162 122  6  .16666667
                101140 140 "BRA" 101 "VEN" 1950 1 3.2 0 0 ""     21 158  3   .3333333
                145160 160 "ARG" 145 "BOL" 1950 1 3.2 0 0 ""      6  18  5         .2
                365710 710 "CHN" 365 "RUS" 1950 1 3.2 0 0 ""     32 123 20        .05
                145155 145 "BOL" 155 "CHL" 1950 1 3.2 0 0 ""     18  31  3   .3333333
                700770 770 "PAK" 700 "AFG" 1950 1 3.2 0 0 ""    112   1  7  .14285715
                355640 640 "TUR" 355 "BUL" 1950 1 3.2 0 0 ""    150  24  5         .2
                220325 325 "ITA" 220 "FRN" 1950 1 3.2 0 0 ""     75  53  9  .11111111
                652660 660 "LEB" 652 "SYR" 1950 1 3.2 0 0 ""     85 143  5         .2
                663666 663 "JOR" 666 "ISR" 1950 1 3.2 0 0 ""     76  74  4        .25
                 70090  70 "MEX"  90 "GUA" 1950 1 3.2 0 0 ""     95  63  4        .25
                770775 770 "PAK" 775 "MYA" 1950 1 3.2 0 0 ""    112 102  6  .16666667
                630700 630 "IRN" 700 "AFG" 1950 1 3.2 0 0 ""     72   1  7  .14285715
                750775 750 "IND" 775 "MYA" 1950 1 3.2 0 0 ""     69 102  6  .16666667
                130135 135 "PER" 130 "ECU" 1950 1 3.2 0 0 ""    115  45  2         .5
                640645 645 "IRQ" 640 "TUR" 1950 1 3.2 0 0 ""     73 150 11   .0909091
                630645 630 "IRN" 645 "IRQ" 1950 1 3.2 0 0 ""     72  73  7  .14285715
                210211 210 "NTH" 211 "BEL" 1950 1 3.2 0 0 ""    110  11  5         .2
                663666 666 "ISR" 663 "JOR" 1950 1 3.2 0 0 ""     74  76  5         .2
                140160 140 "BRA" 160 "ARG" 1950 1 3.2 0 0 ""     21   6  5         .2
                145160 145 "BOL" 160 "ARG" 1950 1 3.2 0 0 ""     18   6  5         .2
                775800 800 "THI" 775 "MYA" 1950 1 3.2 0 0 ""    146 102  6  .16666667
                200205 205 "IRE" 200 "UKG" 1950 1 3.2 0 0 ""     71 153  1          1
                750790 750 "IND" 790 "NEP" 1950 1 3.2 0 0 ""     69 105  2         .5
                710790 710 "CHN" 790 "NEP" 1950 1 3.2 0 0 ""     32 105  2         .5
                325345 325 "ITA" 345 "YUG" 1950 1 3.2 0 0 ""     75 162 12  .08333334
                380385 380 "SWD" 385 "NOR" 1950 1 3.2 0 0 ""    141 109  3   .3333333
                365640 365 "RUS" 640 "TUR" 1950 1 3.2 0 0 ""    123 150 11   .0909091
                365731 365 "RUS" 731 "PRK" 1950 1 3.2 0 0 ""    123 119  3   .3333333
                375385 385 "NOR" 375 "FIN" 1950 1 3.2 0 0 ""    109  52  3   .3333333
                750770 770 "PAK" 750 "IND" 1950 1 3.2 0 0 ""    112  69  6  .16666667
                100140 100 "COL" 140 "BRA" 1950 1 3.2 0 0 ""     33  21  9  .11111111
                135140 140 "BRA" 135 "PER" 1950 1 3.2 0 0 ""     21 115  5         .2
                end
                label values state1 state1
                label def state1 1 "AFG", modify
                label def state1 2 "ALB", modify
                label def state1 6 "ARG", modify
                label def state1 18 "BOL", modify
                label def state1 21 "BRA", modify
                label def state1 24 "BUL", modify
                label def state1 31 "CHL", modify
                label def state1 32 "CHN", modify
                label def state1 33 "COL", modify
                label def state1 38 "CZE", modify
                label def state1 42 "DOM", modify
                label def state1 45 "ECU", modify
                label def state1 52 "FIN", modify
                label def state1 53 "FRN", modify
                label def state1 61 "GRC", modify
                label def state1 66 "HAI", modify
                label def state1 67 "HON", modify
                label def state1 68 "HUN", modify
                label def state1 69 "IND", modify
                label def state1 71 "IRE", modify
                label def state1 72 "IRN", modify
                label def state1 73 "IRQ", modify
                label def state1 74 "ISR", modify
                label def state1 75 "ITA", modify
                label def state1 76 "JOR", modify
                label def state1 85 "LEB", modify
                label def state1 90 "LUX", modify
                label def state1 95 "MEX", modify
                label def state1 102 "MYA", modify
                label def state1 105 "NEP", modify
                label def state1 106 "NIC", modify
                label def state1 109 "NOR", modify
                label def state1 110 "NTH", modify
                label def state1 112 "PAK", modify
                label def state1 113 "PAN", modify
                label def state1 114 "PAR", modify
                label def state1 115 "PER", modify
                label def state1 117 "POL", modify
                label def state1 119 "PRK", modify
                label def state1 122 "ROM", modify
                label def state1 123 "RUS", modify
                label def state1 127 "SAL", modify
                label def state1 141 "SWD", modify
                label def state1 142 "SWZ", modify
                label def state1 143 "SYR", modify
                label def state1 146 "THI", modify
                label def state1 150 "TUR", modify
                label def state1 155 "URU", modify
                label def state1 156 "USA", modify
                label def state1 162 "YUG", modify
                label values state2 state2
                label def state2 1 "AFG", modify
                label def state2 2 "ALB", modify
                label def state2 6 "ARG", modify
                label def state2 11 "BEL", modify
                label def state2 18 "BOL", modify
                label def state2 21 "BRA", modify
                label def state2 24 "BUL", modify
                label def state2 31 "CHL", modify
                label def state2 32 "CHN", modify
                label def state2 33 "COL", modify
                label def state2 35 "COS", modify
                label def state2 38 "CZE", modify
                label def state2 42 "DOM", modify
                label def state2 45 "ECU", modify
                label def state2 46 "EGY", modify
                label def state2 52 "FIN", modify
                label def state2 53 "FRN", modify
                label def state2 63 "GUA", modify
                label def state2 66 "HAI", modify
                label def state2 67 "HON", modify
                label def state2 68 "HUN", modify
                label def state2 69 "IND", modify
                label def state2 72 "IRN", modify
                label def state2 73 "IRQ", modify
                label def state2 74 "ISR", modify
                label def state2 75 "ITA", modify
                label def state2 76 "JOR", modify
                label def state2 85 "LEB", modify
                label def state2 90 "LUX", modify
                label def state2 95 "MEX", modify
                label def state2 100 "MON", modify
                label def state2 102 "MYA", modify
                label def state2 105 "NEP", modify
                label def state2 109 "NOR", modify
                label def state2 114 "PAR", modify
                label def state2 115 "PER", modify
                label def state2 117 "POL", modify
                label def state2 119 "PRK", modify
                label def state2 121 "ROK", modify
                label def state2 122 "ROM", modify
                label def state2 123 "RUS", modify
                label def state2 136 "SPN", modify
                label def state2 141 "SWD", modify
                label def state2 142 "SWZ", modify
                label def state2 143 "SYR", modify
                label def state2 150 "TUR", modify
                label def state2 153 "UKG", modify
                label def state2 158 "VEN", modify
                label def state2 162 "YUG", modify
                I thought by creating the matrices as described above and merging the datasets, I could figure this out, as when I have a matrix that gives me the weight for each country combination and then I multiply this with the rgdppc vector/variable I will get a vector that gives me the average neighboring rgdppc for each country
                Another example would be: I have a dummy variable "genconflict" which ==1 if there is a conflict in a country in a given year and 0 otherwise. a and c are neighbors of b and there is a conflict only in a. These are my matrices: nm= weighted neighbor dummy matrix, c=conflict dummy matrix, wnc=weighted neighboring conflict.
                Code:
                symmetric nm[3,3]
                      a   b   c
                a   0
                b   .5   0
                c   0   .5   0 
                
                c[3,1]
                    c1
                a   1
                b   0
                c   0
                
                wnc[3,1]
                 c1
                a   0
                b  .5
                c   0
                c basically describes my varibale "genconflict" from the first dataset. Everything else, I cant figure out.
                Please let me know if I am completely on the wrong track. I hope this is more understandable and I really appreciate all help I can get, since my work, which I need this for is due in 4 weeks.

                Comment


                • #9
                  I'm not entirely sure what you're trying to do. It now sounds like for each country you want to calculate the average gdppc for all its neighboring countries. This is rather different from what you originally asked for. Anyway, let's move forward.

                  There are some obstacles in your data that you will need to overcome to get this right. For example, using your own example, you will never be able to average Canada and Mexico for the US because Canada appears nowhere in your dyadic data (unless it has some abbreviation that I cannot fathom).

                  There are also 32 different countries in your country data set that are never mentioned in your dyadic data set, so there is no way to ascertain which countries are their neighbors.

                  You will need to fix these gaps in your data in order to get this right.

                  As an aside, you have multiple variables representing the names of the various countries. Some of these are numeric with value labels. But I cannot be sure that the same numeric code corresponds to the same country in each of these different variables. So I am going to work just with state1ab and state2ab and stateid, which are string variables and we don't have to worry about this problem.

                  To get the mean gdppc for each country's neighboring states, all you need to do (once you fix up the data sets) is:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input int statenum str3 stateid int year double rgdppc float genconflict
                  700 "AFG" 1950   892.59 0
                  339 "ALB" 1950  1385.24 0
                  232 "AND" 1950 65967.74 0
                  160 "ARG" 1950  2173.55 0
                  900 "AUL" 1950 11956.39 0
                  305 "AUS" 1950  5194.43 0
                  211 "BEL" 1950  7574.09 0
                  760 "BHU" 1950   620.95 0
                  145 "BOL" 1950  2754.81 0
                  140 "BRA" 1950  1304.71 0
                  355 "BUL" 1950  2284.74 0
                   20 "CAN" 1950 11485.21 0
                  155 "CHL" 1950  3944.64 0
                  710 "CHN" 1950   619.97 1
                  100 "COL" 1950   3070.2 0
                   94 "COS" 1950  3042.58 0
                   40 "CUB" 1950  2831.36 0
                  315 "CZE" 1950  4844.87 0
                  390 "DEN" 1950  8879.06 0
                   42 "DOM" 1950  1539.89 0
                  130 "ECU" 1950  1937.43 0
                  651 "EGY" 1950   643.73 0
                  530 "ETH" 1950    366.5 0
                  375 "FIN" 1950  5596.16 0
                  220 "FRN" 1950  6285.64 0
                  265 "GDR" 1950  7263.72 0
                  260 "GFR" 1950  5083.81 0
                  350 "GRC" 1950   2286.3 0
                   90 "GUA" 1950  2033.68 0
                   41 "HAI" 1950  1454.43 0
                   91 "HON" 1950  1990.01 0
                  310 "HUN" 1950  3431.96 0
                  395 "ICE" 1950  7526.48 0
                  750 "IND" 1950    811.5 1
                  850 "INS" 1950  1130.61 1
                  205 "IRE" 1950  4799.46 0
                  630 "IRN" 1950  2380.23 0
                  645 "IRQ" 1950  1887.58 0
                  666 "ISR" 1950  3227.53 1
                  325 "ITA" 1950  3596.14 0
                  663 "JOR" 1950  2301.35 0
                  740 "JPN" 1950  1764.25 0
                  450 "LBR" 1950  1459.97 0
                  660 "LEB" 1950  3361.38 0
                  223 "LIE" 1950 39637.68 0
                  212 "LUX" 1950 13063.39 0
                   70 "MEX" 1950  4174.62 0
                  221 "MNC" 1950 24181.82 0
                  712 "MON" 1950   601.98 0
                  775 "MYA" 1950   369.96 1
                  775 "MYA" 1950   369.96 1
                  775 "MYA" 1950   369.96 1
                  775 "MYA" 1950   369.96 1
                  775 "MYA" 1950   369.96 1
                  790 "NEP" 1950   686.39 0
                  920 "NEW" 1950  9906.38 0
                   93 "NIC" 1950  1869.28 0
                  385 "NOR" 1950 18279.87 0
                  210 "NTH" 1950  8036.44 0
                  698 "OMA" 1950   862.14 0
                  770 "PAK" 1950  1043.51 0
                   95 "PAN" 1950  1742.67 0
                  150 "PAR" 1950  2033.17 0
                  135 "PER" 1950  2020.58 0
                  840 "PHI" 1950  1199.19 1
                  290 "POL" 1950  3386.29 0
                  235 "POR" 1950  2350.15 0
                  731 "PRK" 1950  1181.81 0
                  732 "ROK" 1950  1181.81 0
                  360 "RUM" 1950  1406.93 0
                  365 "RUS" 1950  3931.53 1
                  560 "SAF" 1950  3933.53 0
                   92 "SAL" 1950   376.75 0
                  670 "SAU" 1950  3087.38 0
                  331 "SNM" 1950 16076.92 0
                  230 "SPN" 1950  3036.58 0
                  780 "SRI" 1950  2084.83 0
                  380 "SWD" 1950  8764.84 0
                  225 "SWZ" 1950 12502.17 0
                  652 "SYR" 1950   3333.7 0
                  713 "TAW" 1950  1267.61 0
                  711 "TBT" 1950  2255.39 0
                  800 "THI" 1950   970.73 0
                  640 "TUR" 1950  2728.94 0
                  200 "UKG" 1950     9130 0
                  165 "URU" 1950  5442.95 0
                    2 "USA" 1950 12776.54 0
                  101 "VEN" 1950 10138.66 0
                  678 "YEM" 1950  1260.69 0
                  345 "YUG" 1950  1976.14 0
                  700 "AFG" 1951   903.66 0
                  339 "ALB" 1951  1446.13 0
                  232 "AND" 1951    74500 0
                  160 "ARG" 1951  2184.75 0
                  900 "AUL" 1951 11220.23 0
                  305 "AUS" 1951  5472.56 0
                  211 "BEL" 1951  7913.39 0
                  760 "BHU" 1951   615.27 0
                  145 "BOL" 1951  2913.73 0
                  140 "BRA" 1951  1308.82 0
                  end
                  tempfile countries
                  save `countries'
                  
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input long dyad int state1no str3 state1ab int state2no str3 state2ab int year byte conttype float(version nstate1ab nstate2ab) str3 statenames long(state1 state2)
                  350640 350 "GRC" 640 "TUR" 1950 1 3.2 0 0 ""     61 150
                  365630 630 "IRN" 365 "RUS" 1950 1 3.2 0 0 ""     72 123
                  630645 645 "IRQ" 630 "IRN" 1950 1 3.2 0 0 ""     73  72
                  339345 345 "YUG" 339 "ALB" 1950 1 3.2 0 0 ""    162   2
                  290315 315 "CZE" 290 "POL" 1950 1 3.2 0 0 ""     38 117
                  651666 666 "ISR" 651 "EGY" 1950 1 3.2 0 0 ""     74  46
                  380385 385 "NOR" 380 "SWD" 1950 1 3.2 0 0 ""    109 141
                  365375 375 "FIN" 365 "RUS" 1950 1 3.2 0 0 ""     52 123
                  652666 652 "SYR" 666 "ISR" 1950 1 3.2 0 0 ""    143  74
                  339345 339 "ALB" 345 "YUG" 1950 1 3.2 0 0 ""      2 162
                  630700 700 "AFG" 630 "IRN" 1950 1 3.2 0 0 ""      1  72
                  212220 220 "FRN" 212 "LUX" 1950 1 3.2 0 0 ""     53  90
                   90091  91 "HON"  90 "GUA" 1950 1 3.2 0 0 ""     67  63
                  710775 710 "CHN" 775 "MYA" 1950 1 3.2 0 0 ""     32 102
                   41042  41 "HAI"  42 "DOM" 1950 1 3.2 0 0 ""     66  42
                  220225 225 "SWZ" 220 "FRN" 1950 1 3.2 0 0 ""    142  53
                  652660 652 "SYR" 660 "LEB" 1950 1 3.2 0 0 ""    143  85
                  652666 666 "ISR" 652 "SYR" 1950 1 3.2 1 0 "ISR"  74 143
                  710775 775 "MYA" 710 "CHN" 1950 1 3.2 0 0 ""    102  32
                  640652 640 "TUR" 652 "SYR" 1950 1 3.2 0 0 ""    150 143
                    2070   2 "USA"  70 "MEX" 1950 1 3.2 0 0 ""    156  95
                  365712 365 "RUS" 712 "MON" 1950 1 3.2 0 0 ""    123 100
                  130135 130 "ECU" 135 "PER" 1950 1 3.2 0 0 ""     45 115
                  135155 155 "CHL" 135 "PER" 1950 1 3.2 0 0 ""     31 115
                  710790 790 "NEP" 710 "CHN" 1950 1 3.2 0 0 ""    105  32
                  220225 220 "FRN" 225 "SWZ" 1950 1 3.2 0 0 ""     53 142
                  365700 365 "RUS" 700 "AFG" 1950 1 3.2 0 0 ""    123   1
                  645652 645 "IRQ" 652 "SYR" 1950 1 3.2 0 0 ""     73 143
                  220230 220 "FRN" 230 "SPN" 1950 1 3.2 0 0 ""     53 136
                  355360 355 "BUL" 360 "ROM" 1950 1 3.2 0 0 ""     24 122
                  360365 365 "RUS" 360 "ROM" 1950 1 3.2 0 0 ""    123 122
                  360365 360 "ROM" 365 "RUS" 1950 1 3.2 0 0 ""    122 123
                  100135 100 "COL" 135 "PER" 1950 1 3.2 0 0 ""     33 115
                  375380 380 "SWD" 375 "FIN" 1950 1 3.2 0 0 ""    141  52
                  140150 140 "BRA" 150 "PAR" 1950 1 3.2 0 0 ""     21 114
                  220325 220 "FRN" 325 "ITA" 1950 1 3.2 0 0 ""     53  75
                   91092  92 "SAL"  91 "HON" 1950 1 3.2 0 0 ""    127  67
                   91093  93 "NIC"  91 "HON" 1950 1 3.2 0 0 ""    106  67
                  225325 325 "ITA" 225 "SWZ" 1950 1 3.2 0 0 ""     75 142
                  150160 160 "ARG" 150 "PAR" 1950 1 3.2 0 0 ""      6 114
                  150160 150 "PAR" 160 "ARG" 1950 1 3.2 0 0 ""    114   6
                  365731 731 "PRK" 365 "RUS" 1950 1 3.2 0 0 ""    119 123
                  652663 663 "JOR" 652 "SYR" 1950 1 3.2 0 0 ""     76 143
                  135155 135 "PER" 155 "CHL" 1950 1 3.2 0 0 ""    115  31
                  365630 365 "RUS" 630 "IRN" 1950 1 3.2 0 0 ""    123  72
                   90092  92 "SAL"  90 "GUA" 1950 1 3.2 0 0 ""    127  63
                  630640 640 "TUR" 630 "IRN" 1950 1 3.2 0 0 ""    150  72
                  660666 660 "LEB" 666 "ISR" 1950 1 3.2 0 0 ""     85  74
                  100101 100 "COL" 101 "VEN" 1950 1 3.2 0 0 ""     33 158
                  212220 212 "LUX" 220 "FRN" 1950 1 3.2 0 0 ""     90  53
                  310360 310 "HUN" 360 "ROM" 1950 1 3.2 0 0 ""     68 122
                  310360 360 "ROM" 310 "HUN" 1950 1 3.2 0 0 ""    122  68
                  355640 355 "BUL" 640 "TUR" 1950 1 3.2 0 0 ""     24 150
                  140165 165 "URU" 140 "BRA" 1950 1 3.2 0 0 ""    155  21
                   94095  95 "PAN"  94 "COS" 1950 1 3.2 0 0 ""    113  35
                  315365 315 "CZE" 365 "RUS" 1950 1 3.2 0 0 ""     38 123
                  100140 140 "BRA" 100 "COL" 1950 1 3.2 0 0 ""     21  33
                  731732 731 "PRK" 732 "ROK" 1950 1 3.2 0 0 ""    119 121
                  145150 145 "BOL" 150 "PAR" 1950 1 3.2 0 0 ""     18 114
                  290365 365 "RUS" 290 "POL" 1950 1 3.2 0 0 ""    123 117
                  640652 652 "SYR" 640 "TUR" 1950 1 3.2 0 0 ""    143 150
                   41042  42 "DOM"  41 "HAI" 1950 1 3.2 0 1 ""     42  66
                  325345 345 "YUG" 325 "ITA" 1950 1 3.2 0 0 ""    162  75
                  645663 645 "IRQ" 663 "JOR" 1950 1 3.2 0 0 ""     73  76
                  290315 290 "POL" 315 "CZE" 1950 1 3.2 0 0 ""    117  38
                  750790 790 "NEP" 750 "IND" 1950 1 3.2 0 0 ""    105  69
                  155160 155 "CHL" 160 "ARG" 1950 1 3.2 0 0 ""     31   6
                  345360 345 "YUG" 360 "ROM" 1950 1 3.2 0 0 ""    162 122
                  101140 140 "BRA" 101 "VEN" 1950 1 3.2 0 0 ""     21 158
                  145160 160 "ARG" 145 "BOL" 1950 1 3.2 0 0 ""      6  18
                  365710 710 "CHN" 365 "RUS" 1950 1 3.2 0 0 ""     32 123
                  145155 145 "BOL" 155 "CHL" 1950 1 3.2 0 0 ""     18  31
                  700770 770 "PAK" 700 "AFG" 1950 1 3.2 0 0 ""    112   1
                  355640 640 "TUR" 355 "BUL" 1950 1 3.2 0 0 ""    150  24
                  220325 325 "ITA" 220 "FRN" 1950 1 3.2 0 0 ""     75  53
                  652660 660 "LEB" 652 "SYR" 1950 1 3.2 0 0 ""     85 143
                  663666 663 "JOR" 666 "ISR" 1950 1 3.2 0 0 ""     76  74
                   70090  70 "MEX"  90 "GUA" 1950 1 3.2 0 0 ""     95  63
                  770775 770 "PAK" 775 "MYA" 1950 1 3.2 0 0 ""    112 102
                  630700 630 "IRN" 700 "AFG" 1950 1 3.2 0 0 ""     72   1
                  750775 750 "IND" 775 "MYA" 1950 1 3.2 0 0 ""     69 102
                  130135 135 "PER" 130 "ECU" 1950 1 3.2 0 0 ""    115  45
                  640645 645 "IRQ" 640 "TUR" 1950 1 3.2 0 0 ""     73 150
                  630645 630 "IRN" 645 "IRQ" 1950 1 3.2 0 0 ""     72  73
                  210211 210 "NTH" 211 "BEL" 1950 1 3.2 0 0 ""    110  11
                  663666 666 "ISR" 663 "JOR" 1950 1 3.2 0 0 ""     74  76
                  140160 140 "BRA" 160 "ARG" 1950 1 3.2 0 0 ""     21   6
                  145160 145 "BOL" 160 "ARG" 1950 1 3.2 0 0 ""     18   6
                  775800 800 "THI" 775 "MYA" 1950 1 3.2 0 0 ""    146 102
                  200205 205 "IRE" 200 "UKG" 1950 1 3.2 0 0 ""     71 153
                  750790 750 "IND" 790 "NEP" 1950 1 3.2 0 0 ""     69 105
                  710790 710 "CHN" 790 "NEP" 1950 1 3.2 0 0 ""     32 105
                  325345 325 "ITA" 345 "YUG" 1950 1 3.2 0 0 ""     75 162
                  380385 380 "SWD" 385 "NOR" 1950 1 3.2 0 0 ""    141 109
                  365640 365 "RUS" 640 "TUR" 1950 1 3.2 0 0 ""    123 150
                  365731 365 "RUS" 731 "PRK" 1950 1 3.2 0 0 ""    123 119
                  375385 385 "NOR" 375 "FIN" 1950 1 3.2 0 0 ""    109  52
                  750770 770 "PAK" 750 "IND" 1950 1 3.2 0 0 ""    112  69
                  100140 100 "COL" 140 "BRA" 1950 1 3.2 0 0 ""     33  21
                  135140 140 "BRA" 135 "PER" 1950 1 3.2 0 0 ""     21 115
                  end
                  label values state1 state1
                  label def state1 1 "AFG", modify
                  label def state1 2 "ALB", modify
                  label def state1 6 "ARG", modify
                  label def state1 18 "BOL", modify
                  label def state1 21 "BRA", modify
                  label def state1 24 "BUL", modify
                  label def state1 31 "CHL", modify
                  label def state1 32 "CHN", modify
                  label def state1 33 "COL", modify
                  label def state1 38 "CZE", modify
                  label def state1 42 "DOM", modify
                  label def state1 45 "ECU", modify
                  label def state1 52 "FIN", modify
                  label def state1 53 "FRN", modify
                  label def state1 61 "GRC", modify
                  label def state1 66 "HAI", modify
                  label def state1 67 "HON", modify
                  label def state1 68 "HUN", modify
                  label def state1 69 "IND", modify
                  label def state1 71 "IRE", modify
                  label def state1 72 "IRN", modify
                  label def state1 73 "IRQ", modify
                  label def state1 74 "ISR", modify
                  label def state1 75 "ITA", modify
                  label def state1 76 "JOR", modify
                  label def state1 85 "LEB", modify
                  label def state1 90 "LUX", modify
                  label def state1 95 "MEX", modify
                  label def state1 102 "MYA", modify
                  label def state1 105 "NEP", modify
                  label def state1 106 "NIC", modify
                  label def state1 109 "NOR", modify
                  label def state1 110 "NTH", modify
                  label def state1 112 "PAK", modify
                  label def state1 113 "PAN", modify
                  label def state1 114 "PAR", modify
                  label def state1 115 "PER", modify
                  label def state1 117 "POL", modify
                  label def state1 119 "PRK", modify
                  label def state1 122 "ROM", modify
                  label def state1 123 "RUS", modify
                  label def state1 127 "SAL", modify
                  label def state1 141 "SWD", modify
                  label def state1 142 "SWZ", modify
                  label def state1 143 "SYR", modify
                  label def state1 146 "THI", modify
                  label def state1 150 "TUR", modify
                  label def state1 155 "URU", modify
                  label def state1 156 "USA", modify
                  label def state1 162 "YUG", modify
                  label values state2 state2
                  label def state2 1 "AFG", modify
                  label def state2 2 "ALB", modify
                  label def state2 6 "ARG", modify
                  label def state2 11 "BEL", modify
                  label def state2 18 "BOL", modify
                  label def state2 21 "BRA", modify
                  label def state2 24 "BUL", modify
                  label def state2 31 "CHL", modify
                  label def state2 32 "CHN", modify
                  label def state2 33 "COL", modify
                  label def state2 35 "COS", modify
                  label def state2 38 "CZE", modify
                  label def state2 42 "DOM", modify
                  label def state2 45 "ECU", modify
                  label def state2 46 "EGY", modify
                  label def state2 52 "FIN", modify
                  label def state2 53 "FRN", modify
                  label def state2 63 "GUA", modify
                  label def state2 66 "HAI", modify
                  label def state2 67 "HON", modify
                  label def state2 68 "HUN", modify
                  label def state2 69 "IND", modify
                  label def state2 72 "IRN", modify
                  label def state2 73 "IRQ", modify
                  label def state2 74 "ISR", modify
                  label def state2 75 "ITA", modify
                  label def state2 76 "JOR", modify
                  label def state2 85 "LEB", modify
                  label def state2 90 "LUX", modify
                  label def state2 95 "MEX", modify
                  label def state2 100 "MON", modify
                  label def state2 102 "MYA", modify
                  label def state2 105 "NEP", modify
                  label def state2 109 "NOR", modify
                  label def state2 114 "PAR", modify
                  label def state2 115 "PER", modify
                  label def state2 117 "POL", modify
                  label def state2 119 "PRK", modify
                  label def state2 121 "ROK", modify
                  label def state2 122 "ROM", modify
                  label def state2 123 "RUS", modify
                  label def state2 136 "SPN", modify
                  label def state2 141 "SWD", modify
                  label def state2 142 "SWZ", modify
                  label def state2 143 "SYR", modify
                  label def state2 150 "TUR", modify
                  label def state2 153 "UKG", modify
                  label def state2 158 "VEN", modify
                  label def state2 162 "YUG", modify
                  
                  tempfile dyads
                  save `dyads'
                  
                  //    THE CODE TO CALCULATE MEAN NEIGHBORING
                  //    COUNTRIES GDPPC STARTS HERE
                  use `dyads', clear
                  //    CREATE A REVERSED DYAD FOR EACH EXISTING ONE
                  //    (SOME ALREADY EXIST, BUT WE NEED THEM ALL)
                  keep state1ab state2ab conttype
                  gen obs_no = _n
                  expand 2
                  by obs_no, sort: gen temp = state1ab if _n == 2
                  by obs_no: replace state1ab = state2ab if _n == 2
                  by obs_no: replace state2ab = temp if _n == 2
                  drop temp obs_no
                  duplicates drop
                  keep if conttype == 1
                  assert state1ab != state2ab
                  rename state1ab stateid
                  
                  //    NOW JOIN COUNTRY DATA WITH NEIGHBOR DYADS
                  joinby stateid using `countries', unmatched(using)
                  tab stateid if _merge == 2
                  
                  //    CALCULATE AVERAGE RGDPC OF ALL NEIGHBORS
                  collapse (mean) mean_nghbr_rgdppc = rgdppc, by(stateid)
                  The beginning of this code is just the -dataex- output to read in your two data sets. The data set in memory at the end of this code will have it. You can then save it as a new data set, or merge it into one of your existing ones, or whatever you need to do with it. As you can see, it does not entail any use of matrices.

                  The last part of your post where you talk about genconflict eludes me completely: I have no idea what you're trying to ask or tell there.



                  Comment


                  • #10
                    Sorry for my bad explanation Clyde! It worked now. Thank you for your help. That will definitely help me progress!

                    Comment


                    • #11
                      Hi everyone, I have a new problem. Would be happy about help!

                      state1ab and state2ab are contiguous neighbor countries

                      statenum1 = numeric country code of state1ab
                      state1ab = abbrevation of country 1
                      statenum = numeric country code of state2ab
                      state2ab = abbrev of country2
                      year = year
                      ongoing = dummy for ongoing internal political conflict in state1ab
                      polity2 = polity score of state1ab
                      mnongoing = average ongoing conflict in all neighboring countries of state1ab
                      (exp: if state1ab==CAN & ongoing==0, state1ab==MEX & ongoing==1, then -> state1ab==USA & mnongoing==0.5)
                      mnpolity2 = average polity score of all neighboring countries of state1ab
                      (exp: if state1ab==CAN & polity2==10, state1ab==MEX & polity2==4, then -> state1ab==USA & mnpolity==7

                      Here is part of my data. The actual dataset contains 166 countries that are each included as a dyad with their neighboring countries.

                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input int statenum1 str3 state1ab int statenum str3 state2ab float(year ongoing) byte polity2 float(mnongoing mnpolity2)
                       2 "USA" 20 "CAN" 1950 0  10  0   2
                       2 "USA" 20 "CAN" 1951 0  10  0   2
                       2 "USA" 20 "CAN" 1952 0  10  0   2
                       2 "USA" 20 "CAN" 1953 0  10  0   2
                       2 "USA" 20 "CAN" 1954 0  10  0   2
                       2 "USA" 20 "CAN" 1955 0  10  0   2
                       2 "USA" 20 "CAN" 1956 0  10  0   2
                       2 "USA" 20 "CAN" 1957 0  10  0   2
                       2 "USA" 20 "CAN" 1958 0  10  0   2
                       2 "USA" 20 "CAN" 1959 0  10  0   2
                       2 "USA" 20 "CAN" 1960 0  10  0   2
                       2 "USA" 20 "CAN" 1961 0  10  0   2
                       2 "USA" 20 "CAN" 1962 0  10  0   2
                       2 "USA" 20 "CAN" 1963 0  10  0   2
                       2 "USA" 20 "CAN" 1964 0  10  0   2
                       2 "USA" 20 "CAN" 1965 0  10  0   2
                       2 "USA" 20 "CAN" 1966 0  10  0   2
                       2 "USA" 20 "CAN" 1967 0  10  0   2
                       2 "USA" 20 "CAN" 1968 0  10  0   2
                       2 "USA" 20 "CAN" 1969 0  10  0   2
                       2 "USA" 20 "CAN" 1970 0  10  0   2
                       2 "USA" 20 "CAN" 1971 0  10  0   2
                       2 "USA" 20 "CAN" 1972 0  10  0   2
                       2 "USA" 20 "CAN" 1973 0  10  0   2
                       2 "USA" 20 "CAN" 1974 0  10  0   2
                       2 "USA" 20 "CAN" 1975 0  10  0   2
                       2 "USA" 20 "CAN" 1976 0  10  0   2
                       2 "USA" 20 "CAN" 1977 0  10  0 3.5
                       2 "USA" 20 "CAN" 1978 0  10  0 3.5
                       2 "USA" 20 "CAN" 1979 0  10  0 3.5
                       2 "USA" 20 "CAN" 1980 0  10  0 3.5
                       2 "USA" 20 "CAN" 1981 0  10  0 3.5
                       2 "USA" 20 "CAN" 1982 0  10  0 3.5
                       2 "USA" 20 "CAN" 1983 0  10  0 3.5
                       2 "USA" 20 "CAN" 1984 0  10  0 3.5
                       2 "USA" 20 "CAN" 1985 0  10  0 3.5
                       2 "USA" 20 "CAN" 1986 0  10  0 3.5
                       2 "USA" 20 "CAN" 1987 0  10  0 3.5
                       2 "USA" 20 "CAN" 1988 0  10  0   5
                       2 "USA" 20 "CAN" 1989 0  10  0   5
                       2 "USA" 20 "CAN" 1990 0  10  0   5
                       2 "USA" 20 "CAN" 1991 0  10  0   5
                       2 "USA" 20 "CAN" 1992 0  10  0   5
                       2 "USA" 20 "CAN" 1993 0  10  0   5
                       2 "USA" 20 "CAN" 1994 0  10 .5   7
                       2 "USA" 20 "CAN" 1995 0  10  0   7
                       2 "USA" 20 "CAN" 1996 0  10 .5   7
                       2 "USA" 20 "CAN" 1997 0  10  0   8
                       2 "USA" 20 "CAN" 1998 0  10  0   8
                       2 "USA" 20 "CAN" 1999 0  10  0   8
                       2 "USA" 20 "CAN" 2000 0  10  0   9
                       2 "USA" 20 "CAN" 2001 1  10  0   9
                       2 "USA" 20 "CAN" 2002 1  10  0   9
                       2 "USA" 20 "CAN" 2003 1  10  0   9
                       2 "USA" 20 "CAN" 2004 1  10  0   9
                       2 "USA" 20 "CAN" 2005 1  10  0   9
                       2 "USA" 20 "CAN" 2006 1  10  0   9
                       2 "USA" 20 "CAN" 2007 1  10  0   9
                       2 "USA" 20 "CAN" 2008 1  10  0   9
                       2 "USA" 20 "CAN" 2009 1  10  0   9
                       2 "USA" 20 "CAN" 2010 1  10  0   9
                       2 "USA" 20 "CAN" 2011 1  10  0   9
                       2 "USA" 20 "CAN" 2012 1  10  0   9
                       2 "USA" 20 "CAN" 2013 1  10  0   9
                       2 "USA" 20 "CAN" 2014 1  10  0   9
                       2 "USA" 20 "CAN" 2015 1  10  0   9
                       2 "USA" 70 "MEX" 1950 0  10  0   2
                       2 "USA" 70 "MEX" 1951 0  10  0   2
                       2 "USA" 70 "MEX" 1952 0  10  0   2
                       2 "USA" 70 "MEX" 1953 0  10  0   2
                       2 "USA" 70 "MEX" 1954 0  10  0   2
                       2 "USA" 70 "MEX" 1955 0  10  0   2
                       2 "USA" 70 "MEX" 1956 0  10  0   2
                       2 "USA" 70 "MEX" 1957 0  10  0   2
                       2 "USA" 70 "MEX" 1958 0  10  0   2
                       2 "USA" 70 "MEX" 1959 0  10  0   2
                       2 "USA" 70 "MEX" 1960 0  10  0   2
                       2 "USA" 70 "MEX" 1961 0  10  0   2
                       2 "USA" 70 "MEX" 1962 0  10  0   2
                       2 "USA" 70 "MEX" 1963 0  10  0   2
                       2 "USA" 70 "MEX" 1964 0  10  0   2
                       2 "USA" 70 "MEX" 1965 0  10  0   2
                       2 "USA" 70 "MEX" 1966 0  10  0   2
                       2 "USA" 70 "MEX" 1967 0  10  0   2
                       2 "USA" 70 "MEX" 1968 0  10  0   2
                       2 "USA" 70 "MEX" 1969 0  10  0   2
                       2 "USA" 70 "MEX" 1970 0  10  0   2
                       2 "USA" 70 "MEX" 1971 0  10  0   2
                       2 "USA" 70 "MEX" 1972 0  10  0   2
                       2 "USA" 70 "MEX" 1973 0  10  0   2
                       2 "USA" 70 "MEX" 1974 0  10  0   2
                       2 "USA" 70 "MEX" 1975 0  10  0   2
                       2 "USA" 70 "MEX" 1976 0  10  0   2
                       2 "USA" 70 "MEX" 1977 0  10  0 3.5
                       2 "USA" 70 "MEX" 1978 0  10  0 3.5
                       2 "USA" 70 "MEX" 1979 0  10  0 3.5
                       2 "USA" 70 "MEX" 1980 0  10  0 3.5
                       2 "USA" 70 "MEX" 1981 0  10  0 3.5
                       2 "USA" 70 "MEX" 1982 0  10  0 3.5
                       2 "USA" 70 "MEX" 1983 0  10  0 3.5
                       2 "USA" 70 "MEX" 1984 0  10  0 3.5
                       2 "USA" 70 "MEX" 1985 0  10  0 3.5
                       2 "USA" 70 "MEX" 1986 0  10  0 3.5
                       2 "USA" 70 "MEX" 1987 0  10  0 3.5
                       2 "USA" 70 "MEX" 1988 0  10  0   5
                       2 "USA" 70 "MEX" 1989 0  10  0   5
                       2 "USA" 70 "MEX" 1990 0  10  0   5
                       2 "USA" 70 "MEX" 1991 0  10  0   5
                       2 "USA" 70 "MEX" 1992 0  10  0   5
                       2 "USA" 70 "MEX" 1993 0  10  0   5
                       2 "USA" 70 "MEX" 1994 0  10 .5   7
                       2 "USA" 70 "MEX" 1995 0  10  0   7
                       2 "USA" 70 "MEX" 1996 0  10 .5   7
                       2 "USA" 70 "MEX" 1997 0  10  0   8
                       2 "USA" 70 "MEX" 1998 0  10  0   8
                       2 "USA" 70 "MEX" 1999 0  10  0   8
                       2 "USA" 70 "MEX" 2000 0  10  0   9
                       2 "USA" 70 "MEX" 2001 1  10  0   9
                       2 "USA" 70 "MEX" 2002 1  10  0   9
                       2 "USA" 70 "MEX" 2003 1  10  0   9
                       2 "USA" 70 "MEX" 2004 1  10  0   9
                       2 "USA" 70 "MEX" 2005 1  10  0   9
                       2 "USA" 70 "MEX" 2006 1  10  0   9
                       2 "USA" 70 "MEX" 2007 1  10  0   9
                       2 "USA" 70 "MEX" 2008 1  10  0   9
                       2 "USA" 70 "MEX" 2009 1  10  0   9
                       2 "USA" 70 "MEX" 2010 1  10  0   9
                       2 "USA" 70 "MEX" 2011 1  10  0   9
                       2 "USA" 70 "MEX" 2012 1  10  0   9
                       2 "USA" 70 "MEX" 2013 1  10  0   9
                       2 "USA" 70 "MEX" 2014 1  10  0   9
                       2 "USA" 70 "MEX" 2015 1  10  0   9
                      20 "CAN"  2 "USA" 1950 0  10  0  10
                      20 "CAN"  2 "USA" 1951 0  10  0  10
                      20 "CAN"  2 "USA" 1952 0  10  0  10
                      20 "CAN"  2 "USA" 1953 0  10  0  10
                      20 "CAN"  2 "USA" 1954 0  10  0  10
                      20 "CAN"  2 "USA" 1955 0  10  0  10
                      20 "CAN"  2 "USA" 1956 0  10  0  10
                      20 "CAN"  2 "USA" 1957 0  10  0  10
                      20 "CAN"  2 "USA" 1958 0  10  0  10
                      20 "CAN"  2 "USA" 1959 0  10  0  10
                      20 "CAN"  2 "USA" 1960 0  10  0  10
                      20 "CAN"  2 "USA" 1961 0  10  0  10
                      20 "CAN"  2 "USA" 1962 0  10  0  10
                      20 "CAN"  2 "USA" 1963 0  10  0  10
                      20 "CAN"  2 "USA" 1964 0  10  0  10
                      20 "CAN"  2 "USA" 1965 0  10  0  10
                      20 "CAN"  2 "USA" 1966 0  10  0  10
                      20 "CAN"  2 "USA" 1967 0  10  0  10
                      20 "CAN"  2 "USA" 1968 0  10  0  10
                      20 "CAN"  2 "USA" 1969 0  10  0  10
                      20 "CAN"  2 "USA" 1970 0  10  0  10
                      20 "CAN"  2 "USA" 1971 0  10  0  10
                      20 "CAN"  2 "USA" 1972 0  10  0  10
                      20 "CAN"  2 "USA" 1973 0  10  0  10
                      20 "CAN"  2 "USA" 1974 0  10  0  10
                      20 "CAN"  2 "USA" 1975 0  10  0  10
                      20 "CAN"  2 "USA" 1976 0  10  0  10
                      20 "CAN"  2 "USA" 1977 0  10  0  10
                      20 "CAN"  2 "USA" 1978 0  10  0  10
                      20 "CAN"  2 "USA" 1979 0  10  0  10
                      20 "CAN"  2 "USA" 1980 0  10  0  10
                      20 "CAN"  2 "USA" 1981 0  10  0  10
                      20 "CAN"  2 "USA" 1982 0  10  0  10
                      20 "CAN"  2 "USA" 1983 0  10  0  10
                      20 "CAN"  2 "USA" 1984 0  10  0  10
                      20 "CAN"  2 "USA" 1985 0  10  0  10
                      20 "CAN"  2 "USA" 1986 0  10  0  10
                      20 "CAN"  2 "USA" 1987 0  10  0  10
                      20 "CAN"  2 "USA" 1988 0  10  0  10
                      20 "CAN"  2 "USA" 1989 0  10  0  10
                      20 "CAN"  2 "USA" 1990 0  10  0  10
                      20 "CAN"  2 "USA" 1991 0  10  0  10
                      20 "CAN"  2 "USA" 1992 0  10  0  10
                      20 "CAN"  2 "USA" 1993 0  10  0  10
                      20 "CAN"  2 "USA" 1994 0  10  0  10
                      20 "CAN"  2 "USA" 1995 0  10  0  10
                      20 "CAN"  2 "USA" 1996 0  10  0  10
                      20 "CAN"  2 "USA" 1997 0  10  0  10
                      20 "CAN"  2 "USA" 1998 0  10  0  10
                      20 "CAN"  2 "USA" 1999 0  10  0  10
                      20 "CAN"  2 "USA" 2000 0  10  0  10
                      20 "CAN"  2 "USA" 2001 0  10  1  10
                      20 "CAN"  2 "USA" 2002 0  10  1  10
                      20 "CAN"  2 "USA" 2003 0  10  1  10
                      20 "CAN"  2 "USA" 2004 0  10  1  10
                      20 "CAN"  2 "USA" 2005 0  10  1  10
                      20 "CAN"  2 "USA" 2006 0  10  1  10
                      20 "CAN"  2 "USA" 2007 0  10  1  10
                      20 "CAN"  2 "USA" 2008 0  10  1  10
                      20 "CAN"  2 "USA" 2009 0  10  1  10
                      20 "CAN"  2 "USA" 2010 0  10  1  10
                      20 "CAN"  2 "USA" 2011 0  10  1  10
                      20 "CAN"  2 "USA" 2012 0  10  1  10
                      20 "CAN"  2 "USA" 2013 0  10  1  10
                      20 "CAN"  2 "USA" 2014 0  10  1  10
                      20 "CAN"  2 "USA" 2015 0  10  1  10
                      41 "HAI" 42 "DOM" 1950 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1951 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1952 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1953 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1954 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1955 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1956 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1957 0  -5  0  -9
                      41 "HAI" 42 "DOM" 1958 0  -8  0  -9
                      41 "HAI" 42 "DOM" 1959 0  -8  0  -9
                      41 "HAI" 42 "DOM" 1960 0  -8  0  -9
                      41 "HAI" 42 "DOM" 1961 0  -9  0   0
                      41 "HAI" 42 "DOM" 1962 0  -9  0   8
                      41 "HAI" 42 "DOM" 1963 0  -9  0   0
                      41 "HAI" 42 "DOM" 1964 0  -9  0   0
                      41 "HAI" 42 "DOM" 1965 0  -9  1   0
                      41 "HAI" 42 "DOM" 1966 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1967 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1968 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1969 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1970 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1971 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1972 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1973 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1974 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1975 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1976 0 -10  0  -3
                      41 "HAI" 42 "DOM" 1977 0  -9  0  -3
                      41 "HAI" 42 "DOM" 1978 0  -9  0   6
                      41 "HAI" 42 "DOM" 1979 0  -9  0   6
                      41 "HAI" 42 "DOM" 1980 0  -9  0   6
                      41 "HAI" 42 "DOM" 1981 0  -9  0   6
                      41 "HAI" 42 "DOM" 1982 0  -9  0   6
                      41 "HAI" 42 "DOM" 1983 0  -9  0   6
                      41 "HAI" 42 "DOM" 1984 0  -9  0   6
                      41 "HAI" 42 "DOM" 1985 0  -9  0   6
                      41 "HAI" 42 "DOM" 1986 0  -8  0   6
                      41 "HAI" 42 "DOM" 1987 0  -8  0   6
                      41 "HAI" 42 "DOM" 1988 0  -7  0   6
                      41 "HAI" 42 "DOM" 1989 1  -6  0   6
                      41 "HAI" 42 "DOM" 1990 0   7  0   6
                      41 "HAI" 42 "DOM" 1991 1  -7  0   6
                      41 "HAI" 42 "DOM" 1992 0  -7  0   6
                      41 "HAI" 42 "DOM" 1993 0  -7  0   6
                      41 "HAI" 42 "DOM" 1994 0   7  0   5
                      41 "HAI" 42 "DOM" 1995 0   7  0   5
                      41 "HAI" 42 "DOM" 1996 0   7  0   8
                      41 "HAI" 42 "DOM" 1997 0   7  0   8
                      41 "HAI" 42 "DOM" 1998 0   7  0   8
                      41 "HAI" 42 "DOM" 1999 0   2  0   8
                      41 "HAI" 42 "DOM" 2000 0  -2  0   8
                      41 "HAI" 42 "DOM" 2001 0  -2  0   8
                      41 "HAI" 42 "DOM" 2002 0  -2  0   8
                      41 "HAI" 42 "DOM" 2003 0  -2  0   8
                      41 "HAI" 42 "DOM" 2004 1   0  0   8
                      41 "HAI" 42 "DOM" 2005 0   3  0   8
                      41 "HAI" 42 "DOM" 2006 0   5  0   8
                      41 "HAI" 42 "DOM" 2007 0   5  0   8
                      41 "HAI" 42 "DOM" 2008 0   5  0   8
                      41 "HAI" 42 "DOM" 2009 0   5  0   8
                      41 "HAI" 42 "DOM" 2010 0   0  0   8
                      41 "HAI" 42 "DOM" 2011 0   0  0   8
                      41 "HAI" 42 "DOM" 2012 0   0  0   8
                      41 "HAI" 42 "DOM" 2013 0   0  0   8
                      41 "HAI" 42 "DOM" 2014 0   0  0   8
                      41 "HAI" 42 "DOM" 2015 0   0  0   8
                      42 "DOM" 41 "HAI" 1950 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1951 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1952 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1953 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1954 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1955 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1956 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1957 0  -9  0  -5
                      42 "DOM" 41 "HAI" 1958 0  -9  0  -8
                      42 "DOM" 41 "HAI" 1959 0  -9  0  -8
                      42 "DOM" 41 "HAI" 1960 0  -9  0  -8
                      42 "DOM" 41 "HAI" 1961 0   0  0  -9
                      42 "DOM" 41 "HAI" 1962 0   8  0  -9
                      42 "DOM" 41 "HAI" 1963 0   0  0  -9
                      42 "DOM" 41 "HAI" 1964 0   0  0  -9
                      42 "DOM" 41 "HAI" 1965 1   0  0  -9
                      42 "DOM" 41 "HAI" 1966 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1967 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1968 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1969 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1970 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1971 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1972 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1973 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1974 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1975 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1976 0  -3  0 -10
                      42 "DOM" 41 "HAI" 1977 0  -3  0  -9
                      42 "DOM" 41 "HAI" 1978 0   6  0  -9
                      42 "DOM" 41 "HAI" 1979 0   6  0  -9
                      42 "DOM" 41 "HAI" 1980 0   6  0  -9
                      42 "DOM" 41 "HAI" 1981 0   6  0  -9
                      42 "DOM" 41 "HAI" 1982 0   6  0  -9
                      42 "DOM" 41 "HAI" 1983 0   6  0  -9
                      42 "DOM" 41 "HAI" 1984 0   6  0  -9
                      42 "DOM" 41 "HAI" 1985 0   6  0  -9
                      42 "DOM" 41 "HAI" 1986 0   6  0  -8
                      42 "DOM" 41 "HAI" 1987 0   6  0  -8
                      42 "DOM" 41 "HAI" 1988 0   6  0  -7
                      42 "DOM" 41 "HAI" 1989 0   6  1  -6
                      42 "DOM" 41 "HAI" 1990 0   6  0   7
                      42 "DOM" 41 "HAI" 1991 0   6  1  -7
                      42 "DOM" 41 "HAI" 1992 0   6  0  -7
                      42 "DOM" 41 "HAI" 1993 0   6  0  -7
                      42 "DOM" 41 "HAI" 1994 0   5  0   7
                      42 "DOM" 41 "HAI" 1995 0   5  0   7
                      42 "DOM" 41 "HAI" 1996 0   8  0   7
                      42 "DOM" 41 "HAI" 1997 0   8  0   7
                      42 "DOM" 41 "HAI" 1998 0   8  0   7
                      42 "DOM" 41 "HAI" 1999 0   8  0   2
                      42 "DOM" 41 "HAI" 2000 0   8  0  -2
                      42 "DOM" 41 "HAI" 2001 0   8  0  -2
                      42 "DOM" 41 "HAI" 2002 0   8  0  -2
                      42 "DOM" 41 "HAI" 2003 0   8  0  -2
                      42 "DOM" 41 "HAI" 2004 0   8  1   0
                      42 "DOM" 41 "HAI" 2005 0   8  0   3
                      42 "DOM" 41 "HAI" 2006 0   8  0   5
                      42 "DOM" 41 "HAI" 2007 0   8  0   5
                      42 "DOM" 41 "HAI" 2008 0   8  0   5
                      42 "DOM" 41 "HAI" 2009 0   8  0   5
                      42 "DOM" 41 "HAI" 2010 0   8  0   0
                      42 "DOM" 41 "HAI" 2011 0   8  0   0
                      42 "DOM" 41 "HAI" 2012 0   8  0   0
                      42 "DOM" 41 "HAI" 2013 0   8  0   0
                      42 "DOM" 41 "HAI" 2014 0   8  0   0
                      42 "DOM" 41 "HAI" 2015 0   8  0   0
                      70 "MEX"  2 "USA" 1950 0  -6  0   6
                      70 "MEX"  2 "USA" 1951 0  -6  0   6
                      70 "MEX"  2 "USA" 1952 0  -6  0   6
                      70 "MEX"  2 "USA" 1953 0  -6  0   6
                      70 "MEX"  2 "USA" 1954 0  -6 .5   2
                      70 "MEX"  2 "USA" 1955 0  -6  0   2
                      70 "MEX"  2 "USA" 1956 0  -6  0   2
                      70 "MEX"  2 "USA" 1957 0  -6  0   2
                      70 "MEX"  2 "USA" 1958 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1959 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1960 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1961 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1962 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1963 0  -6 .5 2.5
                      70 "MEX"  2 "USA" 1964 0  -6  0 2.5
                      70 "MEX"  2 "USA" 1965 0  -6 .5 2.5
                      70 "MEX"  2 "USA" 1966 0  -6 .5 6.5
                      70 "MEX"  2 "USA" 1967 0  -6 .5 6.5
                      70 "MEX"  2 "USA" 1968 0  -6 .5 6.5
                      70 "MEX"  2 "USA" 1969 0  -6 .5 6.5
                      70 "MEX"  2 "USA" 1970 0  -6 .5 5.5
                      70 "MEX"  2 "USA" 1971 0  -6 .5 5.5
                      70 "MEX"  2 "USA" 1972 0  -6 .5 5.5
                      70 "MEX"  2 "USA" 1973 0  -6 .5 5.5
                      70 "MEX"  2 "USA" 1974 0  -6 .5 3.5
                      70 "MEX"  2 "USA" 1975 0  -6 .5 3.5
                      70 "MEX"  2 "USA" 1976 0  -6 .5 3.5
                      70 "MEX"  2 "USA" 1977 0  -3 .5 3.5
                      70 "MEX"  2 "USA" 1978 0  -3 .5 2.5
                      70 "MEX"  2 "USA" 1979 0  -3 .5 2.5
                      70 "MEX"  2 "USA" 1980 0  -3 .5 2.5
                      70 "MEX"  2 "USA" 1981 0  -3 .5 2.5
                      70 "MEX"  2 "USA" 1982 0  -3 .5 1.5
                      70 "MEX"  2 "USA" 1983 0  -3 .5 1.5
                      70 "MEX"  2 "USA" 1984 0  -3 .5   2
                      70 "MEX"  2 "USA" 1985 0  -3 .5 4.5
                      70 "MEX"  2 "USA" 1986 0  -3 .5 6.5
                      70 "MEX"  2 "USA" 1987 0  -3 .5 6.5
                      70 "MEX"  2 "USA" 1988 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1989 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1990 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1991 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1992 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1993 0   0 .5 6.5
                      70 "MEX"  2 "USA" 1994 1   4 .5 6.5
                      70 "MEX"  2 "USA" 1995 0   4 .5 6.5
                      70 "MEX"  2 "USA" 1996 1   4  0   9
                      70 "MEX"  2 "USA" 1997 0   6  0   9
                      70 "MEX"  2 "USA" 1998 0   6  0   9
                      70 "MEX"  2 "USA" 1999 0   6  0   9
                      70 "MEX"  2 "USA" 2000 0   8  0   9
                      70 "MEX"  2 "USA" 2001 0   8 .5   9
                      70 "MEX"  2 "USA" 2002 0   8 .5   9
                      70 "MEX"  2 "USA" 2003 0   8 .5   9
                      70 "MEX"  2 "USA" 2004 0   8 .5   9
                      70 "MEX"  2 "USA" 2005 0   8 .5   9
                      70 "MEX"  2 "USA" 2006 0   8 .5   9
                      70 "MEX"  2 "USA" 2007 0   8 .5   9
                      70 "MEX"  2 "USA" 2008 0   8 .5   9
                      70 "MEX"  2 "USA" 2009 0   8 .5   9
                      70 "MEX"  2 "USA" 2010 0   8 .5   9
                      70 "MEX"  2 "USA" 2011 0   8 .5   9
                      70 "MEX"  2 "USA" 2012 0   8 .5   9
                      70 "MEX"  2 "USA" 2013 0   8 .5   9
                      70 "MEX"  2 "USA" 2014 0   8 .5   9
                      70 "MEX"  2 "USA" 2015 0   8 .5   9
                      70 "MEX" 80 "BLZ" 1981 0  -3 .5 2.5
                      70 "MEX" 80 "BLZ" 1982 0  -3 .5 1.5
                      70 "MEX" 80 "BLZ" 1983 0  -3 .5 1.5
                      70 "MEX" 80 "BLZ" 1984 0  -3 .5   2
                      end

                      I now need to create a new variable mnpolity2_con that shows: If there is conflict in the USA's neighboring states in any given year, what is the average polity score of this country / these countires?


                      I first want to know: is any of the USA's two neighboring countries in conflict in any year?

                      list state1ab state2ab year ongoing mnongoing if state1ab=="USA" & mnongoing > 0
                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input str3(state1ab state2ab) float(year ongoing mnongoing)
                      "USA" "CAN" 1994 0 .5
                      "USA" "CAN" 1996 0 .5
                      "USA" "MEX" 1994 0 .5
                      "USA" "MEX" 1996 0 .5
                      end
                      Since mnongoing= 0.5, one of the USA's neighboring countries is in conflict.

                      I can see that MEX is in conflict in 1994 but Canada is not. MEX's polity2==4, CAN's polity2==10
                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input float year str3 state1ab float ongoing byte polity2
                      1994 "MEX" 1 4
                      end
                      
                      
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input float year str3 state1ab float ongoing byte polity2
                      1994 "CAN" 0 10
                      end
                      My new variable should now show that in 1994, the average polity score of those neihgboring countries that are in conflict (hence MEX) is 4 (4/1). In the hypothetical case of CAN also bein in conflict in 1994, the new variable should show that the average polity score of neighboring countries in conflict is 7 ((4+10)/2).

                      I hope this is understandable and someone can help.
                      Thanks





                      Comment


                      • #12
                        So, I assume that in your data there is only one observation for any dyad in any particular year.

                        Code:
                        isid stateab1 stateab2 year
                        by stateab1 year, sort: egen new_variable = mean(polity2)

                        Comment


                        • #13
                          Well I guess that is the issue. If I take the example USA, there are two dyads in which the USA is defined as state1ab:
                          • state1ab=USA, state2ab=CAN (for 1950 - 2015)
                          • state1ab=USA, state2ab=MEX (for 1950 - 2015)
                          but then there are additional dyads for each neighboring country:
                          • state1ab=CAN, state2ab=USA (for 1950 - 2015)
                          and
                          • state1ab=MEX, state2ab=USA (for 1950 - 2015)
                          • state1ab=MEX, state2ab= GUA (for 1950 - 2015)
                          • state1ab=MEX, state2ab=BLZ (for 1950 - 2015)
                          I guess that is why your suggested syntax says:
                          Code:
                          variables state1ab state2ab year do not uniquely identify the observations
                          I had already tried this before.

                          I also tried to do
                          Code:
                          collapse (mean) mnpolity2_con = polity2 if ongoing>0, by(statenum year) cw
                          which kind of gives the right results, but not for all observations for some reason when I try to check it manually (e.g. it will calculate a mean of 1.8 for RUS in 2014, instead of my manual result -1.5)

                          Comment


                          • #14
                            Ok I found my mistake. Itis not only that the dyad occur more than once but i given some other data, i have some dyads that are duplicates in years. The Russia problem stems from having the 2014 RUS UKR dyad occuring 4 times.

                            Comment


                            • #15
                              Robert PicardClyde Schechter I found this thread and was able to follow it to do about 90% of my work but I'll appreciate your kind help for the remaining. Quick question first:
                              When we generate neighboring countries from post #5 above, how do we drop non-contiguous neighbors? I saw Brazil for example listed as France's neighbor.


                              Question 2:

                              This is my final dataset based on post #5 of this thread:

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input float set int(_ID _ID_pair) str32 country1 str3 iso1 str23 region1 str32 country2 str3 iso2 str23 region2
                              327 140 104 "Afghanistan"            "AFG" "Asia"     "China"                            "CHN" "Asia"    
                              329 108 104 "Afghanistan"            "AFG" "Asia"     "Iran"                             "IRN" "Asia"    
                              322 103 104 "Afghanistan"            "AFG" "Asia"     "Pakistan"                         "PAK" "Asia"    
                              327 105 104 "Afghanistan"            "AFG" "Asia"     "Tajikistan"                       "TJK" "Asia"    
                              330 107 104 "Afghanistan"            "AFG" "Asia"     "Turkmenistan"                     "TKM" "Asia"    
                               28   7 104 "Afghanistan"            "AFG" "Asia"     "Uzbekistan"                       "UZB" "Asia"    
                              412 124 126 "Albania"                "ALB" "Europe"   "Greece"                           "GRC" "Europe"  
                              420 175 126 "Albania"                "ALB" "Europe"   "Kosovo"                           "-99" "Europe"  
                              416 172 126 "Albania"                "ALB" "Europe"   "Macedonia"                        "MKD" "Europe"  
                              418 174 126 "Albania"                "ALB" "Europe"   "Montenegro"                       "MNE" "Europe"  
                              264 165  83 "Algeria"                "DZA" "Africa"   "Libya"                            "LBY" "Africa"  
                              195  53  83 "Algeria"                "DZA" "Africa"   "Mali"                             "MLI" "Africa"  
                              195  54  83 "Algeria"                "DZA" "Africa"   "Mauritania"                       "MRT" "Africa"  
                               13 163  83 "Algeria"                "DZA" "Africa"   "Morocco"                          "MAR" "Africa"  
                              218  56  83 "Algeria"                "DZA" "Africa"   "Niger"                            "NER" "Africa"  
                              264  82  83 "Algeria"                "DZA" "Africa"   "Tunisia"                          "TUN" "Africa"  
                               11   3  83 "Algeria"                "DZA" "Africa"   "Western Sahara"                   "ESH" "Africa"  
                               52  12  75 "Angola"                 "AGO" "Africa"   "Democratic Republic of the Congo" "COD" "Africa"  
                              186  51  75 "Angola"                 "AGO" "Africa"   "Namibia"                          "NAM" "Africa"  
                               52  68  75 "Angola"                 "AGO" "Africa"   "Republic of the Congo"            "COG" "Africa"  
                              250  71  75 "Angola"                 "AGO" "Africa"   "Zambia"                           "ZMB" "Africa"  
                               37  31  10 "Argentina"              "ARG" "Americas" "Bolivia"                          "BOL" "Americas"
                               42  30  10 "Argentina"              "ARG" "Americas" "Brazil"                           "BRA" "Americas"
                               38  11  10 "Argentina"              "ARG" "Americas" "Chile"                            "CHL" "Americas"
                               41 157  10 "Argentina"              "ARG" "Americas" "Paraguay"                         "PRY" "Americas"
                               39  29  10 "Argentina"              "ARG" "Americas" "Uruguay"                          "URY" "Americas"
                              345 146 110 "Armenia"                "ARM" "Asia"     "Azerbaijan"                       "AZE" "Asia"    
                              344 147 110 "Armenia"                "ARM" "Asia"     "Georgia"                          "GEO" "Asia"    
                              338 108 110 "Armenia"                "ARM" "Asia"     "Iran"                             "IRN" "Asia"    
                              343 125 110 "Armenia"                "ARM" "Asia"     "Turkey"                           "TUR" "Asia"    
                              373 154 115 "Austria"                "AUT" "Europe"   "Czechia"                          "CZE" "Europe"  
                              374 122 115 "Austria"                "AUT" "Europe"   "Germany"                          "DEU" "Europe"  
                              370 116 115 "Austria"                "AUT" "Europe"   "Hungary"                          "HUN" "Europe"  
                              375 142 115 "Austria"                "AUT" "Europe"   "Italy"                            "ITA" "Europe"  
                              380 153 115 "Austria"                "AUT" "Europe"   "Slovakia"                         "SVK" "Europe"  
                              379 151 115 "Austria"                "AUT" "Europe"   "Slovenia"                         "SVN" "Europe"  
                              372 128 115 "Austria"                "AUT" "Europe"   "Switzerland"                      "CHE" "Europe"  
                              345 110 146 "Azerbaijan"             "AZE" "Asia"     "Armenia"                          "ARM" "Asia"    
                              433 147 146 "Azerbaijan"             "AZE" "Asia"     "Georgia"                          "GEO" "Asia"    
                              337 108 146 "Azerbaijan"             "AZE" "Asia"     "Iran"                             "IRN" "Asia"    
                              112  19 146 "Azerbaijan"             "AZE" "Asia"     "Russia"                           "RUS" "Europe"  
                              337 125 146 "Azerbaijan"             "AZE" "Asia"     "Turkey"                           "TUR" "Asia"    
                              312  99 100 "Bangladesh"             "BGD" "Asia"     "India"                            "IND" "Asia"    
                              303  94 100 "Bangladesh"             "BGD" "Asia"     "Myanmar"                          "MMR" "Asia"    
                              102 120 112 "Belarus"                "BLR" "Europe"   "Latvia"                           "LVA" "Europe"  
                              349 119 112 "Belarus"                "BLR" "Europe"   "Lithuania"                        "LTU" "Europe"  
                              349 114 112 "Belarus"                "BLR" "Europe"   "Poland"                           "POL" "Europe"  
                              101  19 112 "Belarus"                "BLR" "Europe"   "Russia"                           "RUS" "Europe"  
                              347 113 112 "Belarus"                "BLR" "Europe"   "Ukraine"                          "UKR" "Europe"  
                              174  44 130 "Belgium"                "BEL" "Europe"   "France"                           "-99" "Europe"  
                              400 122 130 "Belgium"                "BEL" "Europe"   "Germany"                          "DEU" "Europe"  
                              428 129 130 "Belgium"                "BEL" "Europe"   "Luxembourg"                       "LUX" "Europe"  
                              400 131 130 "Belgium"                "BEL" "Europe"   "Netherlands"                      "NLD" "Europe"  
                              163  39  40 "Belize"                 "BLZ" "Americas" "Guatemala"                        "GTM" "Americas"
                              129  28  40 "Belize"                 "BLZ" "Americas" "Mexico"                           "MEX" "Americas"
                              207  66  55 "Benin"                  "BEN" "Africa"   "Burkina Faso"                     "BFA" "Africa"  
                              208  56  55 "Benin"                  "BEN" "Africa"   "Niger"                            "NER" "Africa"  
                              209  57  55 "Benin"                  "BEN" "Africa"   "Nigeria"                          "NGA" "Africa"  
                              210  59  55 "Benin"                  "BEN" "Africa"   "Togo"                             "TGO" "Africa"  
                              320 140 101 "Bhutan"                 "BTN" "Asia"     "China"                            "CHN" "Asia"    
                              313  99 101 "Bhutan"                 "BTN" "Asia"     "India"                            "IND" "Asia"    
                               44  10  31 "Bolivia"                "BOL" "Americas" "Argentina"                        "ARG" "Americas"
                              134  30  31 "Bolivia"                "BOL" "Americas" "Brazil"                           "BRA" "Americas"
                               37  11  31 "Bolivia"                "BOL" "Americas" "Chile"                            "CHL" "Americas"
                               43 157  31 "Bolivia"                "BOL" "Americas" "Paraguay"                         "PRY" "Americas"
                               46  32  31 "Bolivia"                "BOL" "Americas" "Peru"                             "PER" "Americas"
                              424 127 171 "Bosnia and Herzegovina" "BIH" "Europe"   "Croatia"                          "HRV" "Europe"  
                              449 174 171 "Bosnia and Herzegovina" "BIH" "Europe"   "Montenegro"                       "MNE" "Europe"  
                              422 173 171 "Bosnia and Herzegovina" "BIH" "Europe"   "Republic of Serbia"               "SRB" "Europe"  
                              183  51  50 "Botswana"               "BWA" "Africa"   "Namibia"                          "NAM" "Africa"  
                              124  26  50 "Botswana"               "BWA" "Africa"   "South Africa"                     "ZAF" "Africa"  
                              182  71  50 "Botswana"               "BWA" "Africa"   "Zambia"                           "ZMB" "Africa"  
                              178  49  50 "Botswana"               "BWA" "Africa"   "Zimbabwe"                         "ZWE" "Africa"  
                               42  10  30 "Brazil"                 "BRA" "Americas" "Argentina"                        "ARG" "Americas"
                              135  31  30 "Brazil"                 "BRA" "Americas" "Bolivia"                          "BOL" "Americas"
                              138  33  30 "Brazil"                 "BRA" "Americas" "Colombia"                         "COL" "Americas"
                              146  44  30 "Brazil"                 "BRA" "Americas" "France"                           "-99" "Europe"  
                              143  42  30 "Brazil"                 "BRA" "Americas" "Guyana"                           "GUY" "Americas"
                               41 157  30 "Brazil"                 "BRA" "Americas" "Paraguay"                         "PRY" "Americas"
                              136  32  30 "Brazil"                 "BRA" "Americas" "Peru"                             "PER" "Americas"
                              142  43  30 "Brazil"                 "BRA" "Americas" "Suriname"                         "SUR" "Americas"
                              132  29  30 "Brazil"                 "BRA" "Americas" "Uruguay"                          "URY" "Americas"
                              138  41  30 "Brazil"                 "BRA" "Americas" "Venezuela"                        "VEN" "Americas"
                              434 149 150 "Brunei"                 "BRN" "Asia"     "Malaysia"                         "MYS" "Asia"    
                              404 124 123 "Bulgaria"               "BGR" "Europe"   "Greece"                           "GRC" "Europe"  
                              408 172 123 "Bulgaria"               "BGR" "Europe"   "Macedonia"                        "MKD" "Europe"  
                              408 173 123 "Bulgaria"               "BGR" "Europe"   "Republic of Serbia"               "SRB" "Europe"  
                              392 118 123 "Bulgaria"               "BGR" "Europe"   "Romania"                          "ROU" "Europe"  
                              404 125 123 "Bulgaria"               "BGR" "Europe"   "Turkey"                           "TUR" "Asia"    
                              207  55  66 "Burkina Faso"           "BFA" "Africa"   "Benin"                            "BEN" "Africa"  
                              228  60  66 "Burkina Faso"           "BFA" "Africa"   "Ghana"                            "GHA" "Africa"  
                              201  61  66 "Burkina Faso"           "BFA" "Africa"   "Ivory Coast"                      "CIV" "Africa"  
                              204  53  66 "Burkina Faso"           "BFA" "Africa"   "Mali"                             "MLI" "Africa"  
                              207  56  66 "Burkina Faso"           "BFA" "Africa"   "Niger"                            "NER" "Africa"  
                              210  59  66 "Burkina Faso"           "BFA" "Africa"   "Togo"                             "TGO" "Africa"  
                               57  12  76 "Burundi"                "BDI" "Africa"   "Democratic Republic of the Congo" "COD" "Africa"  
                              253 170  76 "Burundi"                "BDI" "Africa"   "Rwanda"                           "RWA" "Africa"  
                                7   2  76 "Burundi"                "BDI" "Africa"   "United Republic of Tanzania"      "TZA" "Africa"  
                              291  93  91 "Cambodia"               "KHM" "Asia"     "Laos"                             "LAO" "Asia"    
                              290  92  91 "Cambodia"               "KHM" "Asia"     "Thailand"                         "THA" "Asia"    
                              end
                              ------------------ copy up to and including the previous line ------------------


                              I want to merge it with this dataset below:

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input str44 A_country int A_year str17 D1_Disastertype
                              "Afghanistan"         1991 "Earthquake"       
                              "Afghanistan"         1991 "Flood"            
                              "Afghanistan"         1991 "Earthquake"       
                              "Afghanistan"         1991 "Flood"            
                              "Afghanistan"         1991 "Flood"            
                              "Afghanistan"         1992 "Earthquake"       
                              "Afghanistan"         1992 "Flood"            
                              "Afghanistan"         1992 "Flood"            
                              "Afghanistan"         1993 "Landslide"        
                              "Afghanistan"         1993 "Landslide"        
                              "Afghanistan"         1993 "Storm"            
                              "Afghanistan"         1994 "Earthquake"       
                              "Afghanistan"         1995 "Flood"            
                              "Afghanistan"         1995 "Landslide"        
                              "Afghanistan"         1995 "Flood"            
                              "Afghanistan"         1996 "Earthquake"       
                              "Afghanistan"         1996 "Flood"            
                              "Afghanistan"         1997 "Earthquake"       
                              "Afghanistan"         1997 "Flood"            
                              "Afghanistan"         1997 "Flood"            
                              "Afghanistan"         1997 "Landslide"        
                              "Afghanistan"         1998 "Earthquake"       
                              "Afghanistan"         1998 "Flood"            
                              "Afghanistan"         1998 "Epidemic"         
                              "Afghanistan"         1998 "Epidemic"         
                              "Afghanistan"         1998 "Landslide"        
                              "Afghanistan"         1998 "Earthquake"       
                              "Afghanistan"         1998 "Earthquake"       
                              "Afghanistan"         1999 "Flood"            
                              "Afghanistan"         1999 "Epidemic"         
                              "Afghanistan"         1999 "Epidemic"         
                              "Afghanistan"         1999 "Wildfire"         
                              "Afghanistan"         1999 "Earthquake"       
                              "Afghanistan"         2000 "Epidemic"         
                              "Afghanistan"         2000 "Epidemic"         
                              "Afghanistan"         2000 "Drought"          
                              "Afghanistan"         2000 "Epidemic"         
                              "Afghanistan"         2000 "Epidemic"         
                              "Afghanistan"         2001 "Epidemic"         
                              "Afghanistan"         2001 "Epidemic"         
                              "Afghanistan"         2001 "Earthquake"       
                              "Afghanistan"         2001 "Earthquake"       
                              "Afghanistan"         2002 "Flood"            
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Flood"            
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Earthquake"       
                              "Afghanistan"         2002 "Earthquake"       
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Landslide"        
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Earthquake"       
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Flood"            
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2002 "Flood"            
                              "Afghanistan"         2002 "Epidemic"         
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Earthquake"       
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2003 "Flood"            
                              "Afghanistan"         2004 "Earthquake"       
                              "Afghanistan"         2004 "Flood"            
                              "Afghanistan"         2004 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Storm"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Earthquake"       
                              "Afghanistan"         2005 "Earthquake"       
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Flood"            
                              "Afghanistan"         2005 "Epidemic"         
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Storm"            
                              "Afghanistan"         2006 "Landslide"        
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Drought"          
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Landslide"        
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Earthquake"       
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2006 "Storm"            
                              "Afghanistan"         2006 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2007 "Flood"            
                              "Afghanistan"         2008 "Epidemic"         
                              "Afghanistan"         2008 "Drought"          
                              "Afghanistan"         2008 "Flood"            
                              "Afghanistan"         2009 "Earthquake"       
                              "Afghanistan"         2009 "Flood"            
                              "Afghanistan"         2009 "Flood"            
                              "Afghanistan"         2009 "Landslide"        
                              "Afghanistan"         2009 "Flood"            
                              "Afghanistan"         2010 "Earthquake"       
                              "Afghanistan"         2010 "Landslide"        
                              "Afghanistan"         2010 "Flood"            
                              "Afghanistan"         2010 "Landslide"        
                              "Afghanistan"         2010 "Flood"            
                              "Afghanistan"         2011 "Flood"            
                              "Afghanistan"         2011 "Storm"            
                              "Afghanistan"         2011 "Flood"            
                              "Afghanistan"         2011 "Drought"          
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Landslide"        
                              "Afghanistan"         2012 "Landslide"        
                              "Afghanistan"         2012 "Landslide"        
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Flood"            
                              "Afghanistan"         2012 "Earthquake"       
                              "Afghanistan"         2013 "Flood"            
                              "Afghanistan"         2013 "Flood"            
                              "Afghanistan"         2013 "Earthquake"       
                              "Afghanistan"         2013 "Flood"            
                              "Afghanistan"         2013 "Landslide"        
                              "Afghanistan"         2013 "Flood"            
                              "Afghanistan"         2014 "Flood"            
                              "Afghanistan"         2014 "Flood"            
                              "Afghanistan"         2014 "Storm"            
                              "Afghanistan"         2015 "Landslide"        
                              "Afghanistan"         2015 "Earthquake"       
                              "Afghanistan"         2015 "Landslide"        
                              "Afghanistan"         2015 "Landslide"        
                              "Afghanistan"         2015 "Landslide"        
                              "Afghanistan"         2015 "Earthquake"       
                              "Afghanistan"         2015 "Flood"            
                              "Afghanistan"         2016 "Flood"            
                              "Afghanistan"         2016 "Flood"            
                              "Afghanistan"         2016 "Flood"            
                              "Afghanistan"         2016 "Flood"            
                              "Albania"             1992 "Flood"            
                              "Albania"             1995 "Flood"            
                              "Albania"             1995 "Flood"            
                              "Albania"             1996 "Epidemic"         
                              "Albania"             1997 "Flood"            
                              "Albania"             1998 "Earthquake"       
                              "Albania"             2002 "Storm"            
                              "Albania"             2002 "Flood"            
                              "Albania"             2002 "Epidemic"         
                              "Albania"             2004 "Flood"            
                              "Albania"             2005 "Flood"            
                              "Albania"             2005 "Storm"            
                              "Albania"             2007 "Wildfire"         
                              "Albania"             2009 "Earthquake"       
                              "Albania"             2009 "Flood"            
                              "Albania"             2010 "Flood"            
                              "Albania"             2015 "Flood"            
                              "Albania"             2015 "Flood"            
                              "Albania"             2015 "Flood"            
                              "Albania"             2016 "Flood"            
                              "Algeria"             1991 "Epidemic"         
                              "Algeria"             1992 "Earthquake"       
                              "Algeria"             1992 "Flood"            
                              "Algeria"             1993 "Flood"            
                              "Algeria"             1993 "Landslide"        
                              "Algeria"             1994 "Flood"            
                              "Algeria"             1994 "Flood"            
                              "Algeria"             1994 "Wildfire"         
                              "Algeria"             1994 "Earthquake"       
                              "Algeria"             1996 "Flood"            
                              "Algeria"             1997 "Epidemic"         
                              "Algeria"             1997 "Flood"            
                              "Algeria"             1999 "Earthquake"       
                              "Algeria"             1999 "Flood"            
                              "Algeria"             2000 "Flood"            
                              "Algeria"             2000 "Flood"            
                              "Algeria"             2000 "Storm"            
                              "Algeria"             2000 "Flood"            
                              "Algeria"             2000 "Flood"            
                              "Algeria"             2001 "Flood"            
                              "Algeria"             2002 "Flood"            
                              "Algeria"             2002 "Flood"            
                              "Algeria"             2002 "Flood"            
                              "Algeria"             2003 "Storm"            
                              "Algeria"             2003 "Earthquake"       
                              "Algeria"             2003 "Earthquake"       
                              "Algeria"             2003 "Flood"            
                              "Algeria"             2003 "Flood"            
                              "Algeria"             2003 "Flood"            
                              "Algeria"             2004 "Flood"            
                              "Algeria"             2004 "Earthquake"       
                              "Algeria"             2004 "Earthquake"       
                              "Algeria"             2004 "Flood"            
                              "Algeria"             2005 "Storm"            
                              "Algeria"             2005 "Flood"            
                              "Algeria"             2005 "Flood"            
                              "Algeria"             2006 "Flood"            
                              "Algeria"             2006 "Earthquake"       
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2007 "Wildfire"         
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2007 "Flood"            
                              "Algeria"             2008 "Flood"            
                              "Algeria"             2009 "Flood"            
                              "Algeria"             2009 "Flood"            
                              "Algeria"             2011 "Flood"            
                              "Algeria"             2012 "Flood"            
                              "Algeria"             2012 "Flood"            
                              "Algeria"             2014 "Earthquake"       
                              "Algeria"             2015 "Flood"            
                              "Algeria"             2015 "Flood"            
                              "American Samoa"      2003 "Flood"            
                              "American Samoa"      2004 "Storm"            
                              "American Samoa"      2005 "Storm"            
                              "American Samoa"      2009 "Earthquake"       
                              "Angola"              1995 "Epidemic"         
                              "Angola"              1997 "Drought"          
                              "Angola"              1998 "Epidemic"         
                              "Angola"              1999 "Epidemic"         
                              "Angola"              1999 "Epidemic"         
                              "Angola"              2000 "Landslide"        
                              "Angola"              2000 "Epidemic"         
                              "Angola"              2000 "Flood"            
                              "Angola"              2000 "Flood"            
                              "Angola"              2000 "Flood"            
                              "Angola"              2000 "Flood"            
                              "Angola"              2001 "Flood"            
                              "Angola"              2001 "Flood"            
                              "Angola"              2001 "Epidemic"         
                              "Angola"              2001 "Epidemic"         
                              "Angola"              2001 "Drought"          
                              "Angola"              2002 "Flood"            
                              "Angola"              2003 "Flood"            
                              "Angola"              2003 "Flood"            
                              "Angola"              2004 "Epidemic"         
                              "Angola"              2004 "Flood"            
                              "Angola"              2004 "Flood"            
                              "Angola"              2004 "Drought"          
                              "Angola"              2004 "Flood"            
                              "Angola"              2005 "Flood"            
                              "Angola"              2006 "Epidemic"         
                              "Angola"              2006 "Epidemic"         
                              "Angola"              2006 "Flood"            
                              "Angola"              2007 "Epidemic"         
                              "Angola"              2007 "Flood"            
                              "Angola"              2007 "Flood"            
                              "Angola"              2007 "Epidemic"         
                              "Angola"              2008 "Flood"            
                              "Angola"              2008 "Epidemic"         
                              "Angola"              2008 "Epidemic"         
                              "Angola"              2009 "Flood"            
                              "Angola"              2009 "Epidemic"         
                              "Angola"              2009 "Flood"            
                              "Angola"              2009 "Flood"            
                              "Angola"              2009 "Epidemic"         
                              "Angola"              2010 "Flood"            
                              "Angola"              2010 "Flood"            
                              "Angola"              2010 "Flood"            
                              "Angola"              2011 "Flood"            
                              "Angola"              2011 "Flood"            
                              "Angola"              2011 "Flood"            
                              "Angola"              2011 "Flood"            
                              "Angola"              2012 "Drought"          
                              "Angola"              2013 "Flood"            
                              "Angola"              2015 "Epidemic"         
                              "Angola"              2015 "Flood"            
                              "Angola"              2015 "Flood"            
                              "Angola"              2015 "Flood"            
                              "Angola"              2016 "Flood"            
                              "Angola"              2016 "Flood"            
                              "Angola"              2016 "Flood"            
                              "Angola"              2016 "Flood"            
                              "Anguilla"            1999 "Storm"            
                              "Antigua and Barbuda" 1990 "Storm"            
                              "Antigua and Barbuda" 1995 "Storm"            
                              "Antigua and Barbuda" 1998 "Storm"            
                              "Antigua and Barbuda" 1999 "Storm"            
                              "Antigua and Barbuda" 1999 "Storm"            
                              "Antigua and Barbuda" 2008 "Storm"            
                              "Antigua and Barbuda" 2010 "Storm"            
                              "Argentina"           1990 "Flood"            
                              "Argentina"           1991 "Volcanic activity"
                              "Argentina"           1992 "Epidemic"         
                              "Argentina"           1992 "Flood"            
                              "Argentina"           1992 "Flood"            
                              "Argentina"           1993 "Flood"            
                              "Argentina"           1993 "Flood"            
                              "Argentina"           1993 "Flood"            
                              "Argentina"           1993 "Storm"            
                              "Argentina"           1994 "Wildfire"         
                              "Argentina"           1995 "Storm"            
                              "Argentina"           1995 "Flood"            
                              "Argentina"           1995 "Flood"            
                              "Argentina"           1997 "Flood"            
                              "Argentina"           1998 "Storm"            
                              "Argentina"           1998 "Flood"            
                              "Argentina"           1999 "Wildfire"         
                              "Argentina"           2000 "Wildfire"         
                              "Argentina"           2000 "Storm"            
                              "Argentina"           2000 "Flood"            
                              "Argentina"           2000 "Flood"            
                              "Argentina"           2000 "Flood"            
                              "Argentina"           2000 "Flood"            
                              "Argentina"           2000 "Storm"            
                              "Argentina"           2001 "Flood"            
                              "Argentina"           2001 "Storm"            
                              "Argentina"           2001 "Flood"            
                              "Argentina"           2001 "Storm"            
                              "Argentina"           2001 "Wildfire"         
                              "Argentina"           2001 "Flood"            
                              "Argentina"           2002 "Flood"            
                              "Argentina"           2002 "Earthquake"       
                              "Argentina"           2002 "Flood"            
                              "Argentina"           2002 "Storm"            
                              "Argentina"           2003 "Drought"          
                              "Argentina"           2003 "Storm"            
                              "Argentina"           2003 "Flood"            
                              "Argentina"           2003 "Flood"            
                              "Argentina"           2004 "Flood"            
                              "Argentina"           2004 "Flood"            
                              "Argentina"           2005 "Storm"            
                              "Argentina"           2006 "Flood"            
                              "Argentina"           2007 "Flood"            
                              "Argentina"           2007 "Flood"            
                              "Argentina"           2008 "Volcanic activity"
                              "Argentina"           2008 "Flood"            
                              "Argentina"           2009 "Flood"            
                              "Argentina"           2009 "Flood"            
                              "Argentina"           2009 "Epidemic"         
                              "Argentina"           2009 "Drought"          
                              "Argentina"           2009 "Storm"            
                              "Argentina"           2009 "Landslide"        
                              "Argentina"           2011 "Volcanic activity"
                              "Argentina"           2012 "Storm"            
                              "Argentina"           2012 "Flood"            
                              "Argentina"           2012 "Storm"            
                              "Argentina"           2013 "Storm"            
                              "Argentina"           2013 "Flood"            
                              "Argentina"           2014 "Flood"            
                              "Argentina"           2014 "Flood"            
                              "Argentina"           2014 "Landslide"        
                              "Argentina"           2014 "Flood"            
                              "Argentina"           2015 "Flood"            
                              "Argentina"           2015 "Volcanic activity"
                              "Argentina"           2015 "Flood"            
                              "Argentina"           2015 "Storm"            
                              "Argentina"           2015 "Flood"            
                              "Argentina"           2016 "Flood"            
                              "Argentina"           2016 "Flood"            
                              "Armenia"             1997 "Flood"            
                              "Armenia"             1997 "Earthquake"       
                              "Armenia"             1998 "Flood"            
                              "Armenia"             2000 "Drought"          
                              "Armenia"             2004 "Flood"            
                              "Armenia"             2013 "Storm"            
                              "Armenia"             2016 "Landslide"        
                              "Azerbaijan"          1995 "Flood"            
                              "Azerbaijan"          1995 "Flood"            
                              "Azerbaijan"          1995 "Flood"            
                              "Azerbaijan"          1997 "Flood"            
                              "Azerbaijan"          1998 "Earthquake"       
                              "Azerbaijan"          1999 "Earthquake"       
                              "Azerbaijan"          2000 "Drought"          
                              "Azerbaijan"          2000 "Earthquake"       
                              "Azerbaijan"          2000 "Landslide"        
                              "Azerbaijan"          2003 "Flood"            
                              "Azerbaijan"          2009 "Flood"            
                              end
                              Now what i want to do after merging is generate binary variables for each time a neighbor was hit with a specific disaster type.
                              For example:
                              I want a new variable named neighbor_flood that will have a '1' for each time a country's neighbor was hit with a Flood and '0' otherwise. I will like to do that for Earthquakes, Storms, and Droughts as well but I think one example will be sufficient.

                              Thanks in advance.

                              Comment

                              Working...
                              X