现在我有大量txt文件,每个文件是一天的数据,我需要将每个文件依次读取然后处理后append。问题出现在读取部分
文件名是有规律的,为 ABCD-YYYYMMDD.txt格式,后面YYYYMMDD为时间。我写了这样的程序,发现Stata什么都没做= =data editor是空的。
forvalue i=1/10{
gen date=`i'+7305
format date %td
gen year=year(date)
gen month=month(date)
gen day=day(date)
tostring year month day,replace
replace month=substr("0"+month,-2,2)
replace day=substr("0"+day,-2,2)
gen date1=year+month+day
*生成了文本格式的日期YYYYMMDD
infile ABCD-`date1'.txt,clear
save date_`i'.dta
}
1.是不是我不应该用gen应该用scalar?但是用scalar的话tostring要求必须有variable
2.最后infile运行的时候总是告诉我file ABCD-.txt not found 是什么原因呢?是不是因为clear,如果去掉clear,那么又会显示
you must start with an empty dataset
在这里跪谢了!