Announcement

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

  • Dummy Variable for the incidence of conflict UCDP/PRIO

    Hi, everyone!

    I'm using UCDP/PRIO armed conflict dataset and I want to create a dummy variable (incidence of conflict) that takes 1 if a country is in conflict in that year and 0 if it's not. The main variables in the dataset include countries, conflict ID, start date of a conflict event (YYYY-MM-DD), and its end date (YYYY-MM-DD).

    Can anyone tell me how to create that variable?

    Many thanks,
    Yasmine

  • #2
    Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data.

    Descriptions of data are well-meant but insufficient to help those who want to help you. Even the best descriptions of data are no substitute for an actual example of the data. There are many ways your data might be organized that are consistent with your description, and each would require a somewhat different approach. In order to get a helpful response, you need to show some example data.

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

    When asking for help with code, always show example data.

    By default dataex will output the first 100 observations, but this can be changed using if and in and the obs() option. The output of dataex will look something like the following.
    Code:
    ----------------------- copy starting from the next line -----------------------
    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(x1 x2 x3) float x4 int x5 byte x6
     4195 24 1   2 10 0
    10371 16 3 3.5 17 0
     4647 28 3   2 11 0
    ...
     5079 24 4 2.5  8 1
     8129 21 4 2.5  8 1
     4296 21 3 2.5 16 1
    end
    label values x6 yesno
    label def yesno 0 "No", modify
    label def yesno 1 "Yes", modify
    [/CODE]
    ------------------ copy up to and including the previous line ------------------
    In your dataex output you will select the lines between, but not including, "copy starting from the next line" and "copy up to and including the previous line" and then paste that into your reply. The result presented in your post will look something like the following.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(x1 x2 x3) float x4 int x5 byte x6
     4195 24 1   2 10 0
    10371 16 3 3.5 17 0
     4647 28 3   2 11 0
    ...
     5079 24 4 2.5  8 1
     8129 21 4 2.5  8 1
     4296 21 3 2.5 16 1
    end
    label values x6 yesno
    label def yesno 0 "No", modify
    label def yesno 1 "Yes", modify

    Comment


    • #3
      I am familiar with this UCDP/PRIO armed conflict dataset and I have to say that the documentation and variable descriptions are very poor. The first time I used it, I had to contact two authors who had previously used the dataset and did not get a response. I eventually was able to figure out the variables in the dataset defining civil conflicts, so I am very sympathetic to anyone needing help on this. Here is a way to create a civil conflict dummy:

      Code:
      cap frame create civ
      frame civ{
          use "Data\ucdp-prio-acd-211.dta", clear
          gen country=location
          keep country conflict_id year intensity type_of_conflict
          *CIVIL CONFLICTS IDENTIFIED BY TYPE=3
          keep if type=="3"
          bys country year: keep if _n==1
          foreach var in year intensity type{
              destring `var', replace
          }
          *I ONLY NEEDED 2003-2016
          keep if inrange(year, 2003, 2016)
          gen CIV=1
          contract country year CIV
          *SOME COUNTRY NAMES DIFFER WITH COUNTRY NAMES IN OTHER DATASETS, E.G., WORLD BANK DEVELOPMENT INDICATORS 
          *THUS YOU MAY NEED TO RENAME COUNTRIES BEFORE LINKING WITH OTHER DATA
      }
      frlink m:1 country year, frame(civ)
      frget CIV, from(civ)
      *ONLY COUNTRIES IN UCDP/PRIO HAVE CONFLICTS. WHEN MERGING, THESE TAKE A VALUE OF 1.
      *THOSE NOT MATCHED DO NOT HAVE CONFLICT, SO ASSIGN VALUE 0.
      * "CIV" IS THUS CIVIL CONFLICT DUMMY
      replace CIV=0 if missing(civ)
      lab var CIV "Indicator (=1 if civil war in country during the year, 0 otherwise)"
      drop civ
      frame drop civ

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        I am familiar with this UCDP/PRIO armed conflict dataset and I have to say that the documentation and variable descriptions are very poor. The first time I used it, I had to contact two authors who had previously used the dataset and did not get a response. I eventually was able to figure out the variables in the dataset defining civil conflicts, so I am very sympathetic to anyone needing help on this. Here is a way to create a civil conflict dummy:

        Code:
        cap frame create civ
        frame civ{
        use "Data\ucdp-prio-acd-211.dta", clear
        gen country=location
        keep country conflict_id year intensity type_of_conflict
        *CIVIL CONFLICTS IDENTIFIED BY TYPE=3
        keep if type=="3"
        bys country year: keep if _n==1
        foreach var in year intensity type{
        destring `var', replace
        }
        *I ONLY NEEDED 2003-2016
        keep if inrange(year, 2003, 2016)
        gen CIV=1
        contract country year CIV
        *SOME COUNTRY NAMES DIFFER WITH COUNTRY NAMES IN OTHER DATASETS, E.G., WORLD BANK DEVELOPMENT INDICATORS
        *THUS YOU MAY NEED TO RENAME COUNTRIES BEFORE LINKING WITH OTHER DATA
        }
        frlink m:1 country year, frame(civ)
        frget CIV, from(civ)
        *ONLY COUNTRIES IN UCDP/PRIO HAVE CONFLICTS. WHEN MERGING, THESE TAKE A VALUE OF 1.
        *THOSE NOT MATCHED DO NOT HAVE CONFLICT, SO ASSIGN VALUE 0.
        * "CIV" IS THUS CIVIL CONFLICT DUMMY
        replace CIV=0 if missing(civ)
        lab var CIV "Indicator (=1 if civil war in country during the year, 0 otherwise)"
        drop civ
        frame drop civ
        Thank you so much, Andrew for your reply! Does this variable represent the incidence of conflict (1 if there's a new or ongoing conflict and 0 otherwise) or does it represent the onset of conflict (1 if there's a new conflict in that year and 0 if there's an ongoing one or no conflict)? For example, I want to examine the period from 1999 to 2019, if a country experiences civil conflict in 1999 (start date) and continues to 2002 (end date) then the variable would take the value of 1 from 1999 to 2002 (this is the incidence variable I want to create) while onset would just record 1 in the year 1999 and 0 in 2000, 2001, and 2002.

        Comment


        • #5
          Originally posted by Yasmine Elsayed View Post

          Thank you so much, Andrew for your reply! Does this variable represent the incidence of conflict (1 if there's a new or ongoing conflict and 0 otherwise) or does it represent the onset of conflict (1 if there's a new conflict in that year and 0 if there's an ongoing one or no conflict)? For example, I want to examine the period from 1999 to 2019, if a country experiences civil conflict in 1999 (start date) and continues to 2002 (end date) then the variable would take the value of 1 from 1999 to 2002 (this is the incidence variable I want to create) while onset would just record 1 in the year 1999 and 0 in 2000, 2001, and 2002.
          The code assigns a value of 1 to all conflict years. When you merge it with another dataset, then the unmatched observations take a value of zero as there was no conflict in the unmatched country and year. Note that the data are already in long layout, so the duration variable is irrelevant here. For example:

          Code:
          use "Data\ucdp-prio-acd-211.dta", clear
          gen country=location
          keep if type=="3"
          l conflict_id country year intensity_level type_of_conflict start_date2 ep_end in 12/14
          Res.:

          Code:
          . l conflict_id country year intensity_level type_of_conflict start_date2 ep_end_date in 12/14
          
               +---------------------------------------------------------------------------+
               | confli~d   country   year   intens~l   type_o~t   start_da~2   ep_end_d~e |
               |---------------------------------------------------------------------------|
           12. |    11346     Libya   2013          1          3   2013-11-29              |
           13. |    11346     Libya   2014          1          3   2013-11-29              |
           14. |    11346     Libya   2015          1          3   2013-11-29   2015-04-19 |
               +---------------------------------------------------------------------------+
          Here, the conflict in Libya is from 2013- 2015 and is captured by the year variable.
          Last edited by Andrew Musau; 24 Apr 2022, 16:17.

          Comment


          • #6
            Originally posted by Andrew Musau View Post

            The code assigns a value of 1 to all conflict years. When you merge it with another dataset, then the unmatched observations take a value of zero as there was no conflict in the unmatched country and year. Note that the data are already in long layout, so the duration variable is irrelevant here. For example:

            Code:
            use "Data\ucdp-prio-acd-211.dta", clear
            gen country=location
            keep if type=="3"
            l conflict_id country year intensity_level type_of_conflict start_date2 ep_end in 12/14
            Res.:

            Code:
            . l conflict_id country year intensity_level type_of_conflict start_date2 ep_end_date in 12/14
            
            +---------------------------------------------------------------------------+
            | confli~d country year intens~l type_o~t start_da~2 ep_end_d~e |
            |---------------------------------------------------------------------------|
            12. | 11346 Libya 2013 1 3 2013-11-29 |
            13. | 11346 Libya 2014 1 3 2013-11-29 |
            14. | 11346 Libya 2015 1 3 2013-11-29 2015-04-19 |
            +---------------------------------------------------------------------------+
            Here, the conflict in Libya is from 2013- 2015 and is captured by the year variable.
            Andrew, I can't thank you enough! I think I misunderstood the definition of the Year variable from the codebook, but now I get it. Thank you again for your quick and clear reply.

            Comment


            • #7
              Hi,
              I stumbled across this forum as I am to working with UCDP/PRIO data. I have been trying to generate a dummy variable using Andrew Musau's code however, I keep getting the error variable country not found after the line: frlink m:1 country year, frame(civ). Any advice on how to fix this issue? Thank you!

              Comment


              • #8
                You should have a variable called country and year in both frames. In the UCDP-PRIO dataset, the variable "year" already exists and I generate "country" from the variable "location" (see code in #3)

                use "Data\ucdp-prio-acd-211.dta", clear
                gen country=location
                For your dataset, you should know how the panel identifier and time variable are named. These again should be "country" and "year", respectively.

                Comment

                Working...
                X