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
how to include an if qualifier in an egen command mean() functionI'm working with a time-series panel data set and am attempting to calculate a cross sectional mean …
Can npregress be used to predict mean value of y at given xIf I split the data into training and test group, can I use npregress to predict the mean value in t…
Does an event studies analysis require an OLS model?Hi! I am writing to ask whether an event studies analysis can only happen with a linear regression m…
Pooled OLS, Random Effects and Fixed Effects all giving exact same results!Hi there, I am using a panel data set to investigate the link between inequality and growth. But I…
Check whether coefficients are significant using 2 SE bandsHello, I am reading a paper and it says that the following figure (which draws 2 SE bands) is used …
Subscribe to:
Post Comments (Atom)
0 Response to If-Else Issue
Post a Comment