【发布时间】:2013-01-18 13:49:41
【问题描述】:
我正在尝试读取具有超过 5000 个变量的 stata 和 R 中大小为 320 MB 的 stata 文件。我首先使用stata 读取文件,但它可以读取的最大变量是5000。所以,我不能使用stata 读取stata 文件。我的问题是:
有没有办法使用
stata读取stata文件,首先要求只保留变量(我知道变量),这样变量的数量就少于5000?有没有办法让我在
R中读取这个stata文件?我使用的是 32 位(Vista),R给了我错误。"Error: cannot allocate vector of size 21k.Kb".
我使用以下 R 代码读取文件:
#The stata file is in the webpage: http://www.federalreserve.gov/econresdata/scf/scf_2010survey.htm#STATADAT
#1. set mem 400m
set maxvar 4000
use p10i6.dta, clear
keep x8166 x8167 x8168 x8163 x8164 x2422 x2506 x2606 x2623 x604 x614 x623 x716 x507 x513 x526 x1706 x1705 x1806 x1805 x1906 x1905 x2002 x2012 x1409 x1509 x1609 x1415 x1515 x1615 x1417 x1517 x1617 x1619 x1621 x3124 x3224 x3324 x3129 x3229 x3329 x3335 x3408 x3412 x3416 x3420 x3424 x3428 x4020 x4024 x4028 x4018 x4022 x4026 x4030 x4022 x4026 x4030 x4018 x3507 x3511 x3515 x3519 x3523 x3527 x3506 x3510 x3514 x3518 x3522 x3526 x3529 x3804 x3807 x3810 x3813 x3816 x3818 x3930 x3721 x3821 x3823 x3825 x3827 x3829 x3822 x3824 x3826 x3828 x3830
save p10i6.dta, clear
#2.
library (foreign)
year<-2010
yr <- substr( year , 3 , 4 )
p10i6.dta<-read.dta(paste0( "p" , yr , "i6.dta" ))
saveRDS(p10i6.dta,file=paste0( "p" , yr , "i6.rda" ))
p10i6.rda<-readRDS(paste0( "p" , yr , "i6.rda" ))
【问题讨论】:
-
请提供一个可重现的例子、数据和代码来读取文件。
-
您可以使用跳过选项。 stata.com/support/faqs/data-management/…
-
@PaulHiemstra:我已经用代码更新了问题。
-
尝试
use x8166 x8167 ... using p10i6, clear然后save new_file。 -
@AnthonyDamico:infile 用于 ASCII。我需要有关 stata 文件的帮助。