Hi,
I am trying to program a code that goes through variables pr1-25 (procedure codes) to create a new variable that corresponds to these codes prday1-prday25 where prday contains the day of the procedure performed.
This is the code I am using
gen time_procedure=.
foreach x of numlist 1/25 {
replace time_procedure=prday`x' if i10_pr`x' == "ddd" | i10_pr`x' == "ffff"
}
The issue is that through 1-25 there might be more than one procedure with ddd or ffff codes, so I want the code to run but stop replacing the days if it encountered further procedure through 25
for example
if pr1 is ffff it replaces the day with "5" which is the value in prday1
if the same record has pr5 as ddd or ffff, it will replace the "5" with "10" which is the code in prday5
I don't want that replace to happen, is there anyway to do that?
Related Posts with Making foreach go through multiple variables but stops when one criteria is met
How does David Dorn endorse a m:m merge?Hi everyone, First time poster to this message board. I had a question about David Dorn's commuting…
Not achieving convergence in Latent Class AnalysisHi all, I'm exploring an LCA model with a household survey we've ran. This is looking at the activi…
Calculating averages (industry+year) based on sub sample and then applying them to all firmsHi, I am still quite new to Stata (using Stata 16) and hope to find help here as I do not know how t…
Imputation methodHello, dear Stata community, I have questions related to imputation and winsorization methods that …
Select one observation within group with complex criteriaHello, I have to select only one document per each firmid (sometimes I have one document per firm id…
Subscribe to:
Post Comments (Atom)
0 Response to Making foreach go through multiple variables but stops when one criteria is met
Post a Comment