My first post here, but have used this forum extensively in the past to trouble shoot. However, can't find a solution to my stata problem, if there is one.
I have a series of variables from DX1, DX2, DX3 ... DX25.
Variables DX1 - DX25 have a diagnostic code, which is a string value.
I'm trying to recreate a new variable that searches DX1-25, and pulls the diagnostic codes I am interested in.
Write now, I have this code:
gen AKI=0
forvalues j=1/25{
replace AKI=1 if inlist(DX`j', "5845", "5846", "5847", "5848", "5849")
}
But the problem is, for the inlist function, I can't include more than 5-10 string variables in the "inlist" function. For some new variables I am trying to generate, it will be based on 100s of diagnostic codes. So I thought if I use a macro with my string variables predefined, then I could avoid the 5-10 limit.
I've tried creating the following macro and incorporating it into my loop:
local aki "5845" "5846" "5847" "5848" "5849"
gen AKI=0
forvalues j=1/25{
replace AKI=1 if inlist(DX`j', "`x'")
}
And it doesn't work. The result is "0 real changes made"
Any help you might have would be tremendously appreciated. Thank you.
Related Posts with Local macro in "forvalues" function
How to perform CS-ARDL?Hello all, I want to apply CS-ARDL to my model but as I am new to the field and STATA I could not f…
What does "unrestricted treatment effect heterogeneity" mean?Borusyak, 2021 has a sentence We show that this estimator takes a particularly transparent form…
Why homogeneous treatment assumption leads to "spurious identification of long-run treatment" in staggered DiD?Borusyak, 2021 has a sentence Third, in dynamic specifications, implicit assumptions about trea…
mi estimate sequencingIf I want to use multiple imputation, it seems like this is the first step: Code: mi set mlong mi …
95% confidence intervals around proportions on line graph – usefulness?Hi all, I’m using Stata 15. I’m doing an analysis of applicants for grants. I have a graph showing,…
Subscribe to:
Post Comments (Atom)
0 Response to Local macro in "forvalues" function
Post a Comment