Hi all, I'm using Stata 13.1 on Windows 7.
I am importing data from a number of worksheets in a single Excel file and formatting the data for analysis. I generate a new variable called gender which will have 'male', 'female' or persons depending upon the data sheet the data have been imported from. My aim is to loop through the worksheets, save the results from each worksheet as a temporary file in stata , and then append all of the temporary files - so that I will have males, females and persons all in one final dataset for analysis. I'm trying to find a way of using the value 'male' or 'female' or 'person' from the gender variable and using that with 'tempfile whatever_gender save whatever_gender, but I cant seem to be able to call gender to the tempfile section.
I've tried the following:
I am importing data from a number of worksheets in a single Excel file and formatting the data for analysis. I generate a new variable called gender which will have 'male', 'female' or persons depending upon the data sheet the data have been imported from. My aim is to loop through the worksheets, save the results from each worksheet as a temporary file in stata , and then append all of the temporary files - so that I will have males, females and persons all in one final dataset for analysis. I'm trying to find a way of using the value 'male' or 'female' or 'person' from the gender variable and using that with 'tempfile whatever_gender save whatever_gender, but I cant seem to be able to call gender to the tempfile section.
I've tried the following:
Code:
import excel using SAPE18DT5-mid-2015-ccg-syoa-estimates.xls, describe forvalues sheet=3/`=r(N_worksheet)' { local sheetname=r(worksheet_`sheet') local cellrange = r(range_`sheet') import excel using SAPE18DT5-mid-2015-ccg-syoa-estimates.xls, sheet("`sheetname'") cellrange("`cellrange'") clear di regexr(r(worksheet_`sheet'),".+ ","") g gender = regexr(r(worksheet_`sheet'),".+ ","") tempfile "`regexr(r(worksheet_`sheet'),".+ ","")'" save "file_`sheetname'", replace } append using `Male' append using `Female' append using `Person'
Comment