Stata:使用reshape命令将大量变量转换为长格式

use*_*264 2 stata

我使用Stata/SE 12 maxvars设置为32767并memory设置为640 Mb.我当前的数据集包含9,000个观察值(行数)和16,800个变量(列数v1, v2和最多值v16800).

我想reshape使用以下代码行使用命令将数据集转换为长格式:

reshape long v , i(simulation) j(_count)
Run Code Online (Sandbox Code Playgroud)

Stata给了我错误134:_count占用了太多的值.

观察数量是否存在Stata限制?这可能是什么问题?

Maa*_*uis 5

限制与Stata创建变量_count的方式有关,这涉及到tabulate.这意味着它最多可以处理12,000个变量.你可以做的是将文件分成两部分,重塑每个子文件,然后append再将它们重新分割.像这样的东西:

// create some example data
clear
set obs 5
gen id = _n
forvalues i = 1/10 {
    gen v`i' = rnormal()
}

// split the files:
tempfile orig one two

save `orig'

keep id v1-v5
save `one'

use `orig'
keep id v6-v10
save `two'

// reshape the files separately
use `one'
reshape long v, i(id) j(_count)
save `one', replace

use `two'
reshape long v, i(id) j(_count)
save `two', replace

// bring the files together again
append using `one'
sort id _count
list, sepby(id)
Run Code Online (Sandbox Code Playgroud)