I have the following code in Stata 17 that aims to run a command when the suffixes match. In other words, use days_a with freq_a, days_b with freq_b, and so on. However, it still gives me all combinations from valist 1 and varlist 2. Do you know what is wrong with my code? Thank you!
foreach var1 of varlist days_a days_b days_c days_d days_e days_f days_g days_h days_i days_j {
local var1suffix substr("`var1'", strpos("`var1'", "_")+1, length("`var1'"))
foreach var2 of varlist freq_a freq_b freq_c freq_d freq_e freq_f freq_g freq_h freq_i freq_j {
local var2suffix substr("`var2'", strpos("`var2'", "_")+1, length("`var2'"))
if "`var1suffix'" == "`var2suffix'" & "`var1suffix'" != "" {
total(`var1'), over(`var2')
}
}
}
Related Posts with Creating a loop to run a command when the suffixes match
save psmatch2 outputHello All, This should be a very easy question, but I am unable to figure out how to save the outpu…
Extracting the year from a variable in stataHello, I probably have a very simple query but I can't work out how to solve it I have a variable en…
Create a chart to track changes of exectuive titlesHi Statalist, I want to create a chart to record the title changes of exectuives. For example, I w…
Coding help for regression - dummy variablesHello! Quick question, and very simple to answer. I am wanting to look at whether or not participa…
Summation using If condition to avoid negative valuesHello, I want to write a code that creates a value which is the summation of several rows. I have n…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to run a command when the suffixes match
Post a Comment