Hello All,
I have a rather interesting issue. I am attempting to use some if-else statements for some conditions within a foreach loop. Here is the issue. The syntax that I am posting works beautifully. When I take it to my data, STATA will only read and perform the condition in the first "if" statement. To be clear, the syntax #1 works perfectly, but when I try this with my data, using syntax #2, STATA will only read the first "if" statement and not the second one. I first thought it was a data formatting problem, but the auto.dta variables are: int and byte formats. My data are both byte format. Any ideas how to get this to consistently work across all data?
Syntax #1
sysuse auto.dta, clear
local dv foreign
foreach var of varlist `dv' {
if `var' == mpg {
di 2+2+4/2
}
else if `var' == foreign {
di 10/5
}
}
Syntax #2.
local dv victim
foreach var of varlist `dv' {
if `var' == violence {
di "violence"
}
else if `var' == victim {
di "victim"
}
}
Any help is welcomed. Thank you.
Related Posts with If-Else Issue
Two-level model with vce(cluster) versus three-level modelHi, I'm planning to run some clustered longitudinal analyses and am looking at my modelling options.…
Looping with lagged valuesI'm new to Stata and would highly appreciate any help. I have a panel data. I want to implement for…
pinv vs luinv vs qrinvMata has these different functions for inverting square matrices. The matrices I am inverting are ab…
Stata 16 - Drop just variables and observationsI had Stata 14 and used drop _all command to drop just the variables/observations but keep all the r…
Correlation structure of xtgee: tests of statistical significanceHello Statalisters, I'm using Stata 15.1. My question relates to the "xtgee" commands (in particula…
Subscribe to:
Post Comments (Atom)
0 Response to If-Else Issue
Post a Comment