Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
William Buchanan <william@williambuchanan.net> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: A Tale of Two Macros: Why are these macros producing different results? |

Date |
Mon, 10 Jun 2013 20:58:33 -0700 |

True, but using trace will show the macro expansion. Sent from my iPhone On Jun 10, 2013, at 20:38, Sergiy Radyakin <serjradyakin@gmail.com> wrote: > On Tue, Apr 30, 2013 at 9:18 PM, William Buchanan > <william@williambuchanan.net> wrote: >> You might be able to investigate how things are being processed by using -set trace on-. > > inlist is a function and trace does not show function implementation > (all functions are built-in). > Sergiy > >> >> >> On Apr 30, 2013, at 6:13 PM, William Sankey <wsankey@gmail.com> wrote: >> >>> Thank you for the help, I wonder what the command is processing >>> without the commas? >>> >>> Anyway, I will look to the documentation. Thanks again, >>> >>> On Tue, Apr 30, 2013 at 7:10 PM, Sergiy Radyakin <serjradyakin@gmail.com> wrote: >>>> Documentation for inlist says that for strings only 10 arguments are supported. >>>> So the following is a problem: >>>> >>>> . di inlist("208","150","151", "157", "162", "183","191", "196", >>>> "197", "198", "199", "200", "208") >>>> expression too long >>>> r(130); >>>> >>>> Using spaces instead of commas prevents an error, but does not mean >>>> that Stata is working correctly, it merely stops complaining: >>>> >>>> . di inlist("208","150","151", "157", "162", "183","191", "196", "197" >>>> "198" "199" "200" "208") >>>> 0 >>>> >>>> Using -destring- on the variable you will get better results on list >>>> search of the reals: >>>> . di inlist(208, 150, 151, 157, 162, 183, 191, 196, 197, 198, 199, 200, 208) >>>> 1 >>>> >>>> Using two lists in the program is an additional source of a potential >>>> error. What if you now need to add an additional diagnosis, e.g. 301, >>>> or need to change 191 to 192? >>>> >>>> Best, Sergiy >>>> >>>> >>>> >>>> >>>> On Tue, Apr 30, 2013 at 5:56 PM, William Buchanan >>>> <william@williambuchanan.net> wrote: >>>>> 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 <wsankey@gmail.com> 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/ >>>> * >>>> * 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/ >>> >>> >>> >>> -- >>> 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/ > * > * 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/

**References**:**Re: st: A Tale of Two Macros: Why are these macros producing different results?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

- Prev by Date:
**Re: st: A Tale of Two Macros: Why are these macros producing different results?** - Next by Date:
**Re: st: Heckman Procedure** - Previous by thread:
**Re: st: A Tale of Two Macros: Why are these macros producing different results?** - Index(es):