(stata) Generate a "war" dummy variable using MID dataset
Militarized Interstate Disputes (v5.0)
1) 留國家名稱、戰爭起始年、戰爭結束年
2) 用Loop建立一個wide dataset
forvalues i =1947/2012 {
gen y`i'=0
replace y`i'=1 if war_start==`i'
replace y`i'=1 if war_start<`i' & war_end>=`i'
}
3)由於一個國家可能在不同年份都有戰爭,所以會造成多個ccode。因此我們需要先合併各個變數
collapse (sum) y1947 y1948 y1949 y1950 y1951 y1952 y1953 y1954 y1955 y1956 y1957 y1958 y1959 y1960 y1961 y1962 y1963 y1964 y1965 y1966 y1967 y1968 y1969 y1970 y1971 y1972 y1973 y1974 y1975 y1976 y1977 y1978 y1979 y1980 y1981 y1982 y1983 y1984 y1985 y1986 y1987 y1988 y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012, by(ccode)
4) 把wide資料轉成long 資料格式(country-year)
reshape long y, i(ccode) j(year)
rename y wardummy
Comments
Post a Comment