Hello,
I have a string variable countryiso for a panel, where the 3-letter ISO country code names appear. I do have those 3-letter ISO country code names from 1950-2019. I am interested in inserting the countries 3-letter ISO country code names for the missing years before 1950 and after 2019, where I am missing them in the countryiso variable data
I could do it with repeated pasting in the data, but I have more than 100 countries, so I am thinking a loop may be useful.
Furthermore, I have tried the obvious following, but no luck:
Any suggestion?
And here it is what that looks like the dataset, where in red I've marked the missing values I am interesting to insert/replace with the iso name.
I have a string variable countryiso for a panel, where the 3-letter ISO country code names appear. I do have those 3-letter ISO country code names from 1950-2019. I am interested in inserting the countries 3-letter ISO country code names for the missing years before 1950 and after 2019, where I am missing them in the countryiso variable data
I could do it with repeated pasting in the data, but I have more than 100 countries, so I am thinking a loop may be useful.
Furthermore, I have tried the obvious following, but no luck:
Code:
foreach v in countryiso {
bysort id year : replace `v' = "countryiso" if `v' == ""
}
And here it is what that looks like the dataset, where in red I've marked the missing values I am interesting to insert/replace with the iso name.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float year str97 country str3 countryiso 1945 "United States" "" 1946 "United States" "" 1947 "United States" "" 1948 "United States" "" 1949 "United States" "" 1950 "United States" "USA" 1951 "United States" "USA" 1952 "United States" "USA" 1953 "United States" "USA" 1954 "United States" "USA" 1955 "United States" "USA" 1956 "United States" "USA" 1957 "United States" "USA" 1958 "United States" "USA" 1959 "United States" "USA" 1960 "United States" "USA" 1961 "United States" "USA" 1962 "United States" "USA" 1963 "United States" "USA" 1964 "United States" "USA" 1965 "United States" "USA" 1966 "United States" "USA" 1967 "United States" "USA" 1968 "United States" "USA" 1969 "United States" "USA" 1970 "United States" "USA" 1971 "United States" "USA" 1972 "United States" "USA" 1973 "United States" "USA" 1974 "United States" "USA" 1975 "United States" "USA" 1976 "United States" "USA" 1977 "United States" "USA" 1978 "United States" "USA" 1979 "United States" "USA" 1980 "United States" "USA" 1981 "United States" "USA" 1982 "United States" "USA" 1983 "United States" "USA" 1984 "United States" "USA" 1985 "United States" "USA" 1986 "United States" "USA" 1987 "United States" "USA" 1988 "United States" "USA" 1989 "United States" "USA" 1990 "United States" "USA" 1991 "United States" "USA" 1992 "United States" "USA" 1993 "United States" "USA" 1994 "United States" "USA" 1995 "United States" "USA" 1996 "United States" "USA" 1997 "United States" "USA" 1998 "United States" "USA" 1999 "United States" "USA" 2000 "United States" "USA" 2001 "United States" "USA" 2002 "United States" "USA" 2003 "United States" "USA" 2004 "United States" "USA" 2005 "United States" "USA" 2006 "United States" "USA" 2007 "United States" "USA" 2008 "United States" "USA" 2009 "United States" "USA" 2010 "United States" "USA" 2011 "United States" "USA" 2012 "United States" "USA" 2013 "United States" "USA" 2014 "United States" "USA" 2015 "United States" "USA" 2016 "United States" "USA" 2017 "United States" "USA" 2018 "United States" "USA" 2019 "United States" "USA" 2020 "United States" "" end

Comment