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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
st: AW: Nested loops by observation |

Date |
Mon, 20 Jul 2009 19:01:14 +0200 |

<> The questions are difficult/impossible to answer without an example dataset. Still, I have a hunch that you should look at ************* help reshape ************* Quite often, -reshape- makes seemingly intractable problems surprisingly easy... The -if- commands (like "if dgc`chron_cyc1'_1b_cde == 1" ) that you use evaluate only the first observations in your dataset, nothing else... HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von David Sabapathy Gesendet: Montag, 20. Juli 2009 18:45 An: statalist@hsphsun2.harvard.edu Betreff: st: Nested loops by observation I have a question related to the FAQ "if command versus if qualifier". For each observation in a dataset I need to perform a series of nested loops ("forvalues" / "if") on a longitudinal variable set to evaluate whether a "chronic" medication condition exists. That is, each observation contains multiple years of survey information (the dgc* variables below) which is being analyzed and if a chronic condition exists a new variable "chronic" is set to 1. I can't use the nested commands as shown below in a simplified version of the code as they only work on the first observation. However I also can't use this nested code as a qualifier (i.e. replace chronic = 1 if ...) as syntax does not appear to allow this type of nesting. Is there anyway I can step through observations one by one with this nested code? Any other possible solutions? Thank you for any help you can provide, David gen chronic = . forvalues cycle = 1(1)4 { if dgc`cycle'_1b_cde == 0 { // if no med use cycle i local chron_cyc1 = `cycle' + 1 if dgc`chron_cyc1'_1b_cde == 1 { // if med use cycle_i+1 local chron_cyc2 = `cycle' + 2 if dgc`chron_cyc2'_1b_cde == 1 { // if med use cycle_i+2 if dhc`chron_cyc1'_age >=65 & dhc`chron_cyc2'_age >=65 { // "replace chronic = 2" } else { // "replace chronic = 1" } } } } } This message and any attached documents are only for the use of the intended recipient(s), are confidential and may contain privileged information. Any unauthorized review, use, retransmission, or other disclosure is strictly prohibited. If you have received this message in error, please notify the sender immediately, and then delete the original message. Thank you. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/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/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Nested loops by observation***From:*David Sabapathy <David.Sabapathy@albertahealthservices.ca>

- Prev by Date:
**Re: st: STATA and NHIS weight variables** - Next by Date:
**st: Memory Issue in XP** - Previous by thread:
**st: AW: RE: RE: Nested loops by observation** - Next by thread:
**Re: st: Nested loops by observation** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |