Moses: Please show the code you actually used!
-
Login or Register
- Log in with
local files : dir . files "*" display `"`files'"' foreach f of local files { import excel using `"`f'"', sheet("Sheet1") firstrow save "`"`f'"'.dta", replace clear }
// NEED TO REMOVE .xlsx SUFFIX FROM `f' BEFORE SAVING local save_name: subinstr local f ".xlsx" "" save `"`save_name'"'
local files : dir . files "*" display `"`files'"' foreach f of local files { import excel using `"`f'"', sheet("Sheet1") firstrow local save_name : subinstr local f ".xlsx" "" save `"`save_name'"', replace clear }
local files : dir . files "*.dta" local dir1 "C:\Users\Cliente\Downloads\Josselin\DHS2" local vars hv024 hv000 hv007 tempfile building save `building', emptyok foreach f of local files { use `"`f'"', clear sort `vars' keep `vars' append using `building' save `"`building'"', replace } * label data "jj" save `"`dir1'/jj.dta"', replace
clear tempfile building save `building', emptyok local filenames: dir ""C:\Users\katja\Dropbox\Raw Data" files "*.xlsx*" foreach f of local filenames { import excel using `"`f'"', sheet("Sheet1") firstrow gen source = `"`f'"' display `"Appending `f'"' append using "`building'" save `"`building'"', replace } export excel using 1_large_excel_file.xlsx, replace
clear tempfile building save `building', emptyok cd "C:\Users\katja\Dropbox\Raw Data" local filenames :dir . files "*" foreach f of local filenames { import excel using `"`f'"', sheet("Sheet1") firstrow gen source = `"`f'"' display `"Appending `f'"' tostring age, replace append using "`building'" save `"`building'"', replace clear } Appending alwal_oct22_feb23.xlsx age was byte now str2 file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending gmrv_oct22_feb23.xlsx age already string; no replace (note: variable Consultant was str6, now str8 to accommodate using data's values) (note: variable source was str21, now str22 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending kar_oct22_feb23.xlsx age already string; no replace (note: variable Hospital was str11, now str13 to accommodate using data's values) (note: variable source was str20, now str22 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending kvc_oct22_feb23.xlsx age already string; no replace (note: variable Hospital was str10, now str13 to accommodate using data's values) (note: variable source was str20, now str22 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending madhapur_oct22_feb23.xlsx age was byte now str2 (note: variable Hospital was str8, now str13 to accommodate using data's values) (note: variable age was str2, now str8 to accommodate using data's values) (note: variable Visit was str3, now str6 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending mtc_oct22_feb23.xlsx age already string; no replace (note: variable Hospital was str12, now str13 to accommodate using data's values) (note: variable source was str20, now str25 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved Appending set_oct22_feb23.xlsx age already string; no replace (note: variable Hospital was str9, now str13 to accommodate using data's values) (note: variable age was str6, now str8 to accommodate using data's values) (note: variable Consultant was str7, now str8 to accommodate using data's values) (note: variable source was str20, now str25 to accommodate using data's values) file C:\Users\katja\AppData\Local\Temp\ST_8bc_000001.tmp saved . . export excel using 1_large_excel_file.xlsx, firstrow(variables) replace too few variables specified r(102);
tempfile foo di "`foo'"
use "`building'"
Comment