Announcement

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

  • Matching Actions to Years

    I have to different databases. Database 1 has executive actions in specific years, but this is not continuous (there may be an executive action in 2002 then nothing until 2004) Database 2 has country specific economic performance in specific years. I need somehow to match up the executive action score to the most recent event. So I have database 1 that looks like:

    year | governance_score | country
    1919 5 USA
    1979 12 FRA
    1988 10 USA
    1988 3 DEU
    2001 9 FRA
    2005 11 DEU

    And Database 2
    year | country | GDP
    1990 USA 290
    1991 USA 292
    1992 USA 294
    1995 FRA 143




    How can I keep the governance score consistent for each year after the active date until the country gets a subsequent score and match it to the country?

    Thank you in advance for your help!

  • #2
    Code:
    clear
    input int year byte governance_score str3 country
    1919 5 USA
    1979 12 FRA
    1988 10 USA
    1988 3 DEU
    2001 9 FRA
    2005 11 DEU
    end
    
    tempfile gov
    save `gov'
    
    clear
    input int year str3 country int gdp
    1990 USA 290
    1991 USA 292
    1992 USA 294
    1995 FRA 143
    end
    
    merge 1:1 country year using `gov'
    
    bysort country (year): replace governance_score = governance_score[_n-1] if missing(governance_score)
    drop if _merge == 2
    drop _merge

    Comment

    Working...
    X