Long-time listener, first-time caller, here.
I have panel data at the U.S. county x year level. I have observations of several variables (time-varying county characteristics, namely, the percent of the population in a particular age bucket, ex., percent of population aged 5-14) by decade (in 1940, 1950, 1960, 1970, and 1980) because they are from the Decennial Census. I would like to interpolate values for the years between decades, within county. I have successfully generated linear interpolations using ipolate. However, I would like to try other functional forms, so I would like to interpolate using mipolate and its pchip, spline, and cubic options. For almost each of these options, I run into a different problem.
Pchip gives me this error:
Code:
. mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_pchip) pchip pchipslopes(): 3201 vector required pchip(): - function returned error pchipolate(): - function returned error <istmt>: - function returned error
When I run cubic, it interpolates for some decades, but not all decades. See example scatterplot for Connecticut counties. (A separate, less important problem: the way that the green points are connected with a line seems to be screwy.)
Code:
. mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_cubic) cubic (194535 missing values generated) . twoway connected percent5_14_i_cubic year if statefip==9, ms(+) sort || scatter percent5_14 year if > statefip==9, /// > legend(order(1 "guessed" 2 "known")) xtitle("") yla(, ang(h)) ytitle("Percent of Pop., Age 5-14") > name( cubicp, replace)
Array
Spline seems to run successfully:
Code:
mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_spline) spline twoway connected percent5_14_i_spline year if statefip==9, ms(+) sort || scatter percent5_14 year if statefip==9, /// legend(order(1 "guessed" 2 "known")) xtitle("") yla(, ang(h)) ytitle("Percent of Pop., Age 5-14") name( spline, replace) graph export "/home/nwb/hcproductivity/13_2/percent_5_14_i_spline CT.png", as(png) replace
I am running Stata 14.2 MP on a Linux server.
Any advice and help to get me out of this jam, I would greatly appreciate!
Thanks,
Nate
Code:
foreach i in percent5_14 percent1524 percent2534 percent3544 percent4554 percent5564 percent6574 percent75 { bysort fcounty1: ipolate `i' year, gen(i`i') } xtset fcounty1 year format year %ty sort fcounty1 year mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_spline) spline mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_pchip) pchip mipolate percent5_14 year, by(fcounty1) gen(percent5_14_i_cubic) cubic set scheme s1color twoway connected percent5_14_i year if statefip==9, ms(+) sort || scatter percent5_14 year if statefip==9, /// legend(order(1 "guessed" 2 "known")) xtitle("") yla(, ang(h)) ytitle("Percent of Pop., Age 5-14") name( spline, replace) graph export "/home/nwb/hcproductivity/13_2/percent_5_14_i_spline CT.png", as(png) replace twoway connected percent5_14_i_pchip year if statefip==9, ms(+) sort || scatter percent5_14 year if statefip==9, /// legend(order(1 "guessed" 2 "known")) xtitle("") yla(, ang(h)) ytitle("Percent of Pop., Age 5-14") name( pchip, replace) graph export "/home/nwb/hcproductivity/13_2/percent_5_14_i_pchip CT.png", as(png) replace twoway connected percent5_14_i_cubic year if statefip==9, ms(+) sort || scatter percent5_14 year if statefip==9, /// legend(order(1 "guessed" 2 "known")) xtitle("") yla(, ang(h)) ytitle("Percent of Pop., Age 5-14") name( cubicp, replace) graph export "/home/nwb/hcproductivity/13_2/percent_5_14_i_cubic CT.png", as(png) replace
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double fcounty1 float(year percent5_14 statefip) 0 . . . 1000 . . . 1001 1927 . 1 1001 1928 . 1 1001 1929 . 1 1001 1930 . 1 1001 1931 . 1 1001 1932 . 1 1001 1933 . 1 1001 1934 . 1 1001 1935 . 1 1001 1936 . 1 1001 1937 . 1 1001 1938 . 1 1001 1939 . 1 1001 1940 .23730753 1 1001 1941 . 1 1001 1942 . 1 1001 1943 . 1 1001 1944 . 1 1001 1945 . 1 1001 1946 . 1 1001 1947 . 1 1001 1948 . 1 1001 1949 . 1 1001 1950 .2252282 1 1001 1951 . 1 1001 1952 . 1 1001 1953 . 1 1001 1954 . 1 1001 1955 . 1 1001 1956 . 1 1001 1957 . 1 1001 1958 . 1 1001 1959 . 1 1001 1960 .2381664 1 1001 1961 . 1 1001 1962 . 1 1001 1963 . 1 1001 1964 . 1 1001 1965 . 1 1001 1966 . 1 1001 1967 . 1 1001 1968 . 1 1001 1969 . 1 1001 1970 .25179887 1 1001 1971 . 1 1001 1972 . 1 1001 1973 . 1 1001 1974 . 1 1001 1975 . 1 1001 1976 . 1 1001 1977 . 1 1001 1978 . 1 1001 1979 . 1 1001 1980 .19021048 1 1001 1981 . 1 1001 1982 . 1 1001 1983 . 1 1001 1984 . 1 1001 1985 . 1 1001 1986 . 1 1001 1987 . 1 1001 1988 . 1 1001 1989 . 1 1001 1990 . 1 1001 1991 . 1 1001 1992 . 1 1001 1993 . 1 1001 1994 . 1 1001 1995 . 1 1001 1996 . 1 1001 1997 . 1 1001 1998 . 1 1001 1999 . 1 1001 2000 . 1 1001 2001 . 1 1001 2002 . 1 1001 2003 . 1 1001 2004 . 1 1001 2005 . 1 1001 2006 . 1 1001 2007 . 1 1003 1927 . 1 1003 1928 . 1 1003 1929 . 1 1003 1930 . 1 1003 1931 . 1 1003 1932 . 1 1003 1933 . 1 1003 1934 . 1 1003 1935 . 1 1003 1936 . 1 1003 1937 . 1 1003 1938 . 1 1003 1939 . 1 1003 1940 .2143299 1 1003 1941 . 1 1003 1942 . 1 1003 1943 . 1 end
0 Response to Errors when interpolating panel data using mipolate
Post a Comment