Hey everyone,
I have three files named something like File_1, File_2, File_3, which I am importing and cleaning in a forval i = 1(1)3 {} loop.
File 1 and 3 have a slightly different structure than File 2, so I have included the following if-else statements in the loop to deal with this. The code looks something like this:
forval i = 1(1)3 {
import File_`i', clear
processing common to all files (i.e operations on variables found in all three files)
if `i' == 2 {
separate processing for file 2
(i.e operations on variables only in file 2)
}
else {
processing for files 1 and 3
(i.e operations on variables not in file 2)
}
save File_`i'_clean, replace
}
The first bloc works just fine, but Stata decides to execute the second block regardless of the value of `i'. I'm at my wits end trying to figure out why this could be the cause. Could there be any reason?
I have tried replacing the second block with:
else if `i' == 1 | `i' == 3
if `i' == 1 | `i' == 3
if inlist(`i', 1, 3)
None of these work. Stata just keeps ignoring the logical.
Any help would be appreciated. Unfortunately, I cannot share a concrete example the data since it contains PID. But, errors result from the second block being evaluated for file 2 which does not have those variables.
Related Posts with Stata ignores else condition in if-else blocks within forval loop
[Help] Conditional logit -cmclogit-: marginal effect vs change in predicted probabilities, no matchDear Statalist, Currently using the -cmclogit- command. I've been estimating marginal effects (dydx…
Entrophy balance matching-make sure that treated and controls come from different industriesDear All, I have a question on entrophy balancing matching and would be really grateful if there ar…
How to impute this missing variable?Dear Statalist, I would like to ask some advice about how to impute correctly the end date of a cont…
Data Management - Rate & Proportion & PercentHi, I have a data management question. I have a dataset where the unit of analysis is districts. I …
Color palette installation on stata Hello everyone, These are some color palettes I can use for making beamer slides and after searchin…
Subscribe to:
Post Comments (Atom)
0 Response to Stata ignores else condition in if-else blocks within forval loop
Post a Comment