Hi,
I have 14 Excel datasets in long format with laboratory data from 904 individuals at multiple time points. I am interested in looking at the date of testing but I am having difficulty formating all date variables the same. The appended stata dataset has 58 date variables each named by the type of test (eg UE) test number (eg T1) and ending in date (eg UET1date). I have tried to import, apend and sort the date data with the code below. I thought it would be easiest to parse the dates and reformat from there but I am getting an error, "too many variables specified r(103);"
I would appreciate any suggestions on how to do this.
Many thanks
Caroline
I have 14 Excel datasets in long format with laboratory data from 904 individuals at multiple time points. I am interested in looking at the date of testing but I am having difficulty formating all date variables the same. The appended stata dataset has 58 date variables each named by the type of test (eg UE) test number (eg T1) and ending in date (eg UET1date). I have tried to import, apend and sort the date data with the code below. I thought it would be easiest to parse the dates and reformat from there but I am getting an error, "too many variables specified r(103);"
I would appreciate any suggestions on how to do this.
Many thanks
Caroline
Code:
cd "<file location>" save appended_data.dta, empty replaceforeach file of local f { import excel "<file location>'", sheet("Data") firstrow clear foreach date_var in *date { capture: tostring `date_var', replace } append using appended_data.dta, force save appended_data.dta, replace } foreach date_var in *date { split `date_var', parse(/) //* breaks up the date variable using the / as the separator*/ replace `date_var'1="0"+`date_var'1 if strlen(`date_var'1)<2 /*adding leading 0 to the day*/ replace `date_var'2="0"+`date_var'2 if strlen(`date_var'2)<2 /*adding leading 0 to the month*/ gen `date_var'_fixed=`date_var'1 + `date_var'2 + `date_var'3 replace `date_var'=`date_var'_fixed drop `date_var'_fixed `date_var'1 `date_var'2 `date_var'3 }
Comment