Hello Statamasters,
This is my first post! So thank you in advance for your attention.
I am trying to import data from raw survey instruments, and that involves extracting datapoints from the same cells in many different (around 300) excel sheets divided in 21 excel files. Since all of the sheets have the same structure, the challenge is to write a stata code to loop over all those sheets, extract the same information, and produce a dataset with 300 observations, one for each sheet.
I wrote already the code for each sheet. It goes like this:
I repeated this routine on and on to get stata to produce a single observation with 128 variables out of each excel sheet (the data points are scattered all over the spreadsheet so I had to extract cell for cell instead of using some other efficient method).
The idea I had so far was to create another dataset with one variable for the full file paths for all the spreadsheets and variables containing the sheets in each different file, and run a levelsof macro to connect this dataset with the .do file described above. Nevertheless, my attempts at this idea are not bearing fruits. Any different ideas?
Thank you very much.
Henrique
This is my first post! So thank you in advance for your attention.
I am trying to import data from raw survey instruments, and that involves extracting datapoints from the same cells in many different (around 300) excel sheets divided in 21 excel files. Since all of the sheets have the same structure, the challenge is to write a stata code to loop over all those sheets, extract the same information, and produce a dataset with 300 observations, one for each sheet.
I wrote already the code for each sheet. It goes like this:
Code:
import excel using "/Users/henrique/excelfile1.xlsx", sheet(sheet1) cellrange(R167:R167) rename R q128 label var q128 "Você tem energia elétrica?" save "survey.dta", replace clear import excel using "/Users/henrique/excelfile1.xlsx", sheet(sheet1) cellrange(R166:R166) rename R q127 label var q127 "Qual nível de Bolsa Família você recebe?" merge 1:1 _n using "survey.dta" drop _merge save "survey.dta", replace clear
The idea I had so far was to create another dataset with one variable for the full file paths for all the spreadsheets and variables containing the sheets in each different file, and run a levelsof macro to connect this dataset with the .do file described above. Nevertheless, my attempts at this idea are not bearing fruits. Any different ideas?
Thank you very much.
Henrique
Comment