Hi,
so my files are like that :
..._paris_visites.20-10-08.csv
..._madrid_visites.20-10-08.csv
..._london_visites.20-10-08.csv
..._paris_events.20-10-08.csv
..._madrid_events.20-10-08.csv
..._london_events.20-10-08.csv
and i want to append and to have only 2 files like that :
..._visites.20-10-08.dta
..._events.20-10-08.dta
i found a loop to do that, but i need to do 1 loop for every type of documents (i don't have only visites and events but more)
For example for "visites" mine is :
local date_export="20-10-08"
clear
save ..._visites.`date_export'.dta, emptyok replace
local myfiles: dir "`pwd'" files "*visites.`date_export'.csv"
foreach x in `myfiles' {
import delimited "`x'", stringcols(_all) clear
gen Site= "`x'"
replace Site="Paris" if strpos(Site,"beni")
replace Site="Madrid" if strpos(Site,"butembo")
replace Site="London" if strpos(Site,"mangina")
append using ..._visites.`date_export'.dta
save ..._visites.`date_export'.dta,replace
}
It works, but i would like to get one loop (or 2, one in the other i never did it)
I would like to change "visites" by an other loop
I tried this but it doesn't work
local date_export="20-10-08"
local type_data="visites events"
foreach x of local `type_data' {
clear
save ..._`x'.`date_export'.dta, emptyok replace
local myfiles_`x' : dir "`pwd'" files "*`x'.`date_export'.csv"
foreach y in `myfiles_`x'' {
import delimited "`y'", stringcols(_all) clear
gen Site= "`y'"
replace Site="Paris" if strpos(Site,"paris")
replace Site="Madrid" if strpos(Site,"madrid")
replace Site="London" if strpos(Site,"london")
append using vainqueurs_`x'.`date_export'.dta
save vainqueurs_`x'.`date_export'.dta,replace
}
}
I have this error : { required r(100);
Ty !
Related Posts with Loop and files management with append
Import a folder with .csv filesDear all, I am trying to import a folder with .csv files to stata. Each file corresponds to a month…
Problem with the graph of xtline when using "i." commandHi all, I encountered some problems in graphing xtline diagrams. Here is my code: Code: preserve c…
Testing for Interaction, C.Logistic Regression: Colinearity and no observations identifiedHello, I am trying to assess for interaction where the primary association is estrogen use and endo…
Why do we estimate and report unadjusted regression results besides adjusted?Hi All, I hope you are well! I am wondering why do we have to estimate and report unadjusted regres…
The odds ratio, SD, CI is too small?Hello, I am doing a logistic to check the odds ratio between binary outcome and continuous variable…
Subscribe to:
Post Comments (Atom)
0 Response to Loop and files management with append
Post a Comment