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
Question about data synchronizationDear all, Good morning. I have a question about the data synchronization. Please see the picture bel…
'var' invalid name even though it is in my codeHello! I am trying to test for interaction terms in my propensity model however I get the error mess…
Control for age in Diff-in-diff regressionHi, I´m doing a difference-in-difference regression on the causal relationship between income tax a…
intra class correlationHi to everybody, I' ve to calculate ICC (It's for me the first time) I'll try to explain the proble…
Creating "total number of births by sex", using dummies for sexDear All, I would like to create a variable for total number of male birth and total number of fema…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to run a command when the suffixes match
Post a Comment