I am trying to append some excel files using the xls2dta command. Currently, the folders are organized in the following manner
C:/Dropbox/Research/Data/VDSA/XX/*var*.xlsx
where XX represents a state abbreviation. Within each XX folder are a bunch of excel files, each containing observations for a single variable.
My goal is to create variable specific Stata datasets where each file will have all observations for that variable from every state.
The code I have written up is reproduced below. The hurdle is that while each excel file has only one sheet, the sheet name themselves vary by file. I don't care what the sheet name is but I need to figure out a way to ignore the sheetname.
Whenever I run the module below, I get an error saying:
option sheets() not allowed.
Here is my code:
clear
cd "C:/Dropbox/Research/Data/VDSA Data"
local vdsafname "aesr agri_implements area_prod cia fert_consumption fert_prices fhp fodder hyv june_julyaug landuse lgp livestock mai market_road nca_gca_nia_gia normal_rainfall operational_holdings pet population sia soil_type wages"
local statename "AP AS BH CH GJ HP HR JH KA KE MH MP OD PU RJ TN UK UP WB"
foreach x of local vdsafname{
foreach s of local statename{
xls2dta : import excel "`s'/dt_`x'_a_web.xlsx", sheets(*) firstrow
drop DISTNAME
xls2dta , save("`x'.dta") : append
}
}
I am not interested in saving the individual files as Stata files. My goal is to append them and create one large file.
Thanks.
C:/Dropbox/Research/Data/VDSA/XX/*var*.xlsx
where XX represents a state abbreviation. Within each XX folder are a bunch of excel files, each containing observations for a single variable.
My goal is to create variable specific Stata datasets where each file will have all observations for that variable from every state.
The code I have written up is reproduced below. The hurdle is that while each excel file has only one sheet, the sheet name themselves vary by file. I don't care what the sheet name is but I need to figure out a way to ignore the sheetname.
Whenever I run the module below, I get an error saying:
option sheets() not allowed.
Here is my code:
clear
cd "C:/Dropbox/Research/Data/VDSA Data"
local vdsafname "aesr agri_implements area_prod cia fert_consumption fert_prices fhp fodder hyv june_julyaug landuse lgp livestock mai market_road nca_gca_nia_gia normal_rainfall operational_holdings pet population sia soil_type wages"
local statename "AP AS BH CH GJ HP HR JH KA KE MH MP OD PU RJ TN UK UP WB"
foreach x of local vdsafname{
foreach s of local statename{
xls2dta : import excel "`s'/dt_`x'_a_web.xlsx", sheets(*) firstrow
drop DISTNAME
xls2dta , save("`x'.dta") : append
}
}
I am not interested in saving the individual files as Stata files. My goal is to append them and create one large file.
Thanks.
Comment