简体   繁体   English

STATA:复制多个变量的插值

[英]STATA: Replicate interpolation for multiple variables

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_1 v_country_2 v_country_2 v_country_3 v_country_3 ... ... v_country_234 v_country_234
Canada加拿大 2000 2000 1005 1005 1051 1051 1052 1052 --- --- 1120 1120
Canada加拿大 2001 2001年 --- ---
Canada加拿大 2002 2002年 --- ---
Canada加拿大 2003 2003年 --- ---
Canada加拿大 2004 2004年 2000 2000 3500 3500 500 500 --- --- 10562 10562
Korea韩国 2000 2000 1005 1005 1051 1051 1052 1052 --- --- 1120 1120
Korea韩国 2001 2001年 --- ---
Korea韩国 2002 2002年 --- ---
Korea韩国 2003 2003年 --- ---
Korea韩国 2004 2004年 2000 2000 3500 3500 500 500 --- --- 10562 10562
... ... ... ... ... ... ... ... ... ... --- --- .... ……
Uganda乌干达 2000 2000 1005 1005 1051 1051 1052 1052 --- --- 1120 1120
Uganda乌干达 2001 2001年 --- ---
Uganda乌干达 2002 2002年 --- ---
Uganda乌干达 2003 2003年 --- ---
Uganda乌干达 2004 2004年 2000 2000 3500 3500 500 500 --- --- 10562 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.但是,我有 234 个变量……所以几乎不可能手动复制这项工作。

Could you please teach me how to do it?你能教我怎么做吗? (I know there is a command foreach that is meant to do replication.) (我知道有一个用于复制的命令 foreach。)

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.查看help dshelp forvalueshelp foreach了解更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM