Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: A Tale of Two Macros: Why are these macros producing different results?
From
William Buchanan <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: A Tale of Two Macros: Why are these macros producing different results?
Date
Tue, 30 Apr 2013 14:56:41 -0700
You have statements that are not equivalent. Check the commas in your first statement.
HTH,
Billy
Sent from my iPhone
On Apr 30, 2013, at 14:37, William Sankey <[email protected]> wrote:
> Good afternoon Statalist,
>
> I have two different macros operating in different parts of my code, I
> developed the first macro some time ago and the second macro recently.
> I believed these two macros would give me the same output, however,
> the first macro is producing far fewer observations than the second.
> It seems that the first is misclassifying observations and though I
> cannot figure out why.
>
> Any help in deciphering what it is about the first macro that would
> produce fewer observations would be much appreciated.
>
> The first macro set:
>
> ***Cancer
>
> local ICD2 "Diagnosis1 Diagnosis2 Diagnosis3 Diagnosis4 Diagnosis5"
> foreach X of varlist `ICD2' {
> replace cancer =1 if inlist(`X',"150","151" "157" "162" "183" "191"
> "196" "197" "198" "199" "200" "208")
> }
>
> local PMT2 "Diagnosis_PMT_A_1 Diagnosis_PMT_A_2 Diagnosis_PMT_B_1
> Diagnosis_PMT_B_2 Diagnosis_PMT_C_1 Diagnosis_PMT_C_2"
>
> foreach X of varlist `PMT2' {
> replace cancer =1 if inlist(`X',"150","151" "157" "162" "183" "191"
> "196" "197" "198" "199" "200" "208")
> }
>
>
> The second macro set:
>
> gen DIAG_1 = Diagnosis1
> gen DIAG_2 = Diagnosis2
> gen DIAG_3 = Diagnosis3
> gen DIAG_4 = Diagnosis4
> gen DIAG_5 = Diagnosis5
>
> gen ALT_A_1 = Diagnosis_PMT_A_1
> gen ALT_A_2 = Diagnosis_PMT_A_2
> gen ALT_B_1 = Diagnosis_PMT_B_1
> gen ALT_B_2 = Diagnosis_PMT_B_2
> gen ALT_C_1 = Diagnosis_PMT_C_1
> gen ALT_C_2 = Diagnosis_PMT_C_2
> ***Cancer
>
> forval j = 1/5 {
> replace cancer=1 ///
> if inlist(DIAG_`j',"150","151", "157", "162", "183","191",
> "196", "197" "198" "199" "200" "208")
> }
>
> local letter "A B C"
> foreach i in `letter' {
> forval e = 1/2 {
> replace cancer=1 ///
> if (inlist(ALT_`i'_`e',"150","151" "157" "162" "183" "191"
> "196" "197" "198" "199" "200" "208")
> }
> }
> }
>
> Thanks,
> Will
>
> --
> William J. Sankey
> Johns Hopkins University
> MA Public Policy '12
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/