我有 114 个带有 .dat 扩展名的文件要转换为 Stata/SE 并附加,其中包含大量变量(从 81 到 16800 不等)。我已将最大变量数重置为32000 set maxvar 32000
(ucla.edu/stat/stata/faq/append_many_files.htmset mem 500m
代码如下所示:
cd "C:\Users\..."
! dir *.dat /a-d /b >d:\Stata_directory\Products_batchfilelist.txt
file open myfile using "d:\Stata_directory\Products_batchfilelist.txt", read
file read myfile line
drop _all
insheet using `line', comma names
gen n = substr("`line'",10,1)
gen m = substr("`line'",12,1)
gen playersnum = substr("`line'",14,1)
save Products_merged.dta, replace
drop _all
file read myfile line
while r(eof)==0 {
insheet using `line', comma names
gen n = substr("`line'",10,1)
gen m = substr("`line'",12,1)
generate playersnum = substr("`line'",14,1)
save `line'.dta, replace
append using Products_merged.dta
save Products_merged.dta,replace
drop _all
file read myfile line
}
问题是,虽然n,m,playersnum
从文件名中提取的变量存在于每个单独的文件中,但它们在最终的“Products_merged.dta”文件中消失了。谁能告诉我可能是什么问题以及是否可以使用 Stata/SE 解决?