【发布时间】:2022-01-25 04:10:45
【问题描述】:
我在 Stata 中插入多个变量,但不知道如何有效地进行。
我的数据是这样的
| 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 |
如您所见,我的数据包括多个国家/地区。所以,我需要按国家/地区插入变量。
我可以使用代码很容易地插入一个变量:
by cow: ipolate v_country_1 year, gen(v_country_1_ipo)
但是,我有 234 个变量...所以几乎不可能手动复制这项工作。
你能教我怎么做吗? (我知道有一个用于复制的命令 foreach。)
【问题讨论】:
标签: loops interpolation stata replication