Hey all.
This is my third question in a short period of time and I should finally have it all figured out by now.... except from one thing. I am using foreach to loop through a list of datasets to do a lot of things but I have found one very specific complication; when I use the local to call on all .dta-files in the directory and then use that macro two save a graph as png, it gives me an error, since it's trying to save the graph as datasetname.dta.png (since the local contains datasetname.dta). Below is a condensed code that recreates the problem.
I thought that one way of solving it would be to somehow edit the local macro to remove the ".dta" suffix and then just write
instead of
, but I am not quite sure how to fix this, since all the datasets have different names. I thought it was maybe possible to remove the last 4 characters of the local by doing this:
But it tells me that: "dataset1 not found". This is the name of the first dataset in the folder, so it is able to call upon it but something is still wrong.
Thanks in advance guys.
This is my third question in a short period of time and I should finally have it all figured out by now.... except from one thing. I am using foreach to loop through a list of datasets to do a lot of things but I have found one very specific complication; when I use the local to call on all .dta-files in the directory and then use that macro two save a graph as png, it gives me an error, since it's trying to save the graph as datasetname.dta.png (since the local contains datasetname.dta). Below is a condensed code that recreates the problem.
Code:
clear cd "C:\Users\rolfll\Dropbox\QTI\Runde 5\dta" local dta : dir . files "*.dta" foreach x of local dta { use `x' hist var1 graph export `x'.png, replace
Code:
use `x'.dta
Code:
use `x'
Code:
clear cd "C:\Users\rolfll\Dropbox\QTI\Runde 5\dta" local dta : dir . files "*.dta" foreach f of local dta{ local dta1 = substr("`f'", 1, length("`f'")-4) di `dta1' }
Thanks in advance guys.
Comment