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
Frequency weight in a before and after graph (twoway pccapsym)Hi. I have a data set where I look at number of events before and after a certain time-point. I wan…
Selected Graphs for Panel Data CategoriesHi, I'm new to Stata and I'm trying to get some panel-times series graphs for selected countries. Sp…
Creating a new variable based on the value of other variablesHi all, I have created a categorical variable (values 1 through 5) in excel based on certain charac…
attndHi I am using survey data and I want to use sample weights for estimating attnd and attk after runni…
Calculate normalized euclidean distanceHi all, The Euclidean distance matrix could be obtained by using Code: use http://www.stata-press.…
Subscribe to:
Post Comments (Atom)
0 Response to If-Else Issue
Post a Comment