I am interpolating multiple variables, but don't know how to do it efficiently.
My data looks like this
Country | Year | v_country_1 | v_country_2 | v_country_3 | ... | v_country_234 |
---|---|---|---|---|---|---|
Canada | 2000 | 1005 | 1051 | 1052 | --- | 1120 |
Canada | 2001 | --- | ||||
Canada | 2002 | --- | ||||
Canada | 2003 | --- | ||||
Canada | 2004 | 2000 | 3500 | 500 | --- | 10562 |
Korea | 2000 | 1005 | 1051 | 1052 | --- | 1120 |
Korea | 2001 | --- | ||||
Korea | 2002 | --- | ||||
Korea | 2003 | --- | ||||
Korea | 2004 | 2000 | 3500 | 500 | --- | 10562 |
... | ... | ... | ... | ... | --- | .... |
Uganda | 2000 | 1005 | 1051 | 1052 | --- | 1120 |
Uganda | 2001 | --- | ||||
Uganda | 2002 | --- | ||||
Uganda | 2003 | --- | ||||
Uganda | 2004 | 2000 | 3500 | 500 | --- | 10562 |
As you can see my data includes multiple countries. So, I need to interpolate the variables by country.
I can interpolate the one variable very easily by using the code:
by cow: ipolate v_country_1 year, gen(v_country_1_ipo)
But, I have 234 variables... so it is almost impossible to replicate this work by hand.
Could you please teach me how to do it? (I know there is a command foreach that is meant to do replication.)
ds v_country_*
foreach x in `r(varlist)' {
by country: ipolate `x' year, gen(`x'_ipo)
}
// OR
forvalues i = 1/234 {
by country: ipolate v_country_`i' year, gen(v_country_`i'_ipo)
}
Check out help ds
and help forvalues
or help foreach
for further details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.