Announcement

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

  • How to replace the value of a variable between different years when the years is not fixed numbers and I don't know the value of the years?

    Hello. The dataset is part of a large dataset and is shown in the attached graph ( and the code between clear and end). I want to do two jobs. First, I need to create a variable named "havePTA" and then replace "havePTA" with 1 if the years are after the year when the country pair signed an agreement, and the country didn't drop all the agreements they signed before. Second, for each country pair each year, I need to replace the two depth variables, depth_index and depth_rasch, with the value related to the highest non-withdrawal agreement. How can I do the two jobs? Can you take a look?
    For example, in the dataset of the graph,
    I want to create a variable named "havePTA" , and replace it with 1 in the year 2003 and the years after 2003 because the country pair that signed the agreement in 2003 didn't drop it
    And replace depth_index with .4 after year 2003, and replace depth_rasch with .64424986 in year 2004 and 2005, then replace depth_rasch with .76104419 after year 2006

    Explanation of variables:
    year: calendar year
    ISO1: country name
    ISO2: country name
    number: Unique ID for each trade agreement in the dataset (a means accession,_1 means withdrawal)
    withdrawl: dummy variable equals 1 if one of the countries of the country pair withdraws the agreement in the year
    pair_id: country id
    year_sign: the year when the country pair sign or withdraw a trade agreement
    signPTA: dummy variable equals 1 if both of the countries of the country pair sign a trade agreement

    base_treaty: for example, in year 2007, number is 193_1, and base_treaty is 193, it means that the country pair withdraw trade agreement number 193

    clear
    input str5(ISO2 ISO1) float year str6 number byte depth_index double depth_rasch int base_treaty float(withdrawal year_sign pair_id signPTA)
    "ALB" "BGR" 2000 "" . . . 0 . 1046 0
    "ALB" "BGR" 2001 "" . . . 0 . 1046 0
    "ALB" "BGR" 2002 "" . . . 0 . 1046 0
    "ALB" "BGR" 2003 "6" 4 .644249863074339 6 0 2003 1046 1
    "ALB" "BGR" 2004 "" . . . 0 . 1046 0
    "ALB" "BGR" 2005 "" . . . 0 . 1046 0
    "ALB" "BGR" 2006 "193a" 4 .761044193146642 192 0 2006 1046 1
    "ALB" "BGR" 2007 "193_1" . . 193 1 2007 1046 1
    "ALB" "BGR" 2008 "" . . . 0 . 1046 0
    "ALB" "BGR" 2009 "" . . . 0 . 1046 0
    "ALB" "BGR" 2010 "" . . . 0 . 1046 0
    end
    Attached Files
Working...
X