I am trying to create a loop that copies specific files (which have a specific identifier at the end of the filename) from a list of folders to another folder using Windows shell commands. However, I am having trouble working with the local macros in Stata. I have tried troubleshooting this with a variety of different ways but get various issues.
1) When I run the commands below:
local folder "folder"
local version "version10"
di "C:\...\`folder'\*`version'.*"
Stata shows this:
C:\...`folder'\*version10.*
It is unclear to me why the `folder' does not return value the assigned to the local macro and also why the backslash somehow disappears.
2) I tried to get around this by combining the local macros as follows:
local folder "folder"
local version "version10"
local path = "C:\..." + "`folder'" + "\*" + "`version'" + ".*"
di "`path'"
This works and returns the following path:
C:\...\folder\*version10.*
However, when I tried to create a loop to do this for all the folders as follows:
local names "a" "b" "c" (These would be the folder names)
local version "version10"
foreach folder of local names {
local path = "C:\..." + "`folder'" + "\*" + "`version'" + ".*"
di "`path'"
}
I get a "too few quotes" error, even though this is the same exact command that I ran previously that returns the correct path.
I would really appreciate any help with this.
Related Posts with Combining local macros in Stata
[putdocx] problem about tostring with comma, table fontHello. I am making some report using -putdocx- command. My data is like following result table. C…
post-estimation/testparm with xtscc regression using time and fixed effects dummiesHello, I am currently working with an unbalanced panel data set. We would like run some regressions…
Difference in Difference estimate with staggered coverage and increasing treatment intensityHi I am new to the Stata forum so apologies if this question has been asked before. I have panel da…
CrosstabulationsHi- Why does the sample size need to be larger if the table is bigger than a 2x2 for cross tabulatio…
Combining texp(ln(_t))* and texp(_t >=* *) for time dependent variables on Survival Analysis!!Hello! my dear STATA users! I have run a cox regression model dealing with time-varying covariates…
Subscribe to:
Post Comments (Atom)
0 Response to Combining local macros in Stata
Post a Comment