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

From |
Sergiy Radyakin <serjradyakin@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Obtain the list of variables used in an if condition |

Date |
Wed, 12 Aug 2009 16:02:59 -0400 |

Dear All, how do I get the list of variables used in an if-condition passed to my Stata program? obviously all sorts of logical expressions and functions are permitted in the if-condition. program foobar syntax [if] // ... determine which vars are used in the if-condition and put them in var_list ... // ... compute something ... end I am looking for an elegant solution, the one that would not involve, say, dropping vars one by one and checking if the expression is still computable. One solution is to replace all the ! ~ ^ + - * / = < > ] and ) to spaces, then look at the tokens left. Those with ( immediately following are function names, those with [ or a space immidetely following are variables. (and we can use -capture confirm variable- to check that). Is there any problem with such an approach? (e.g. factor variables in Stata 11?) Is there a better (or a standard/existing) approach to the problem? Thank you, Sergiy Radyakin * * 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/

**Follow-Ups**:**st: RE: Obtain the list of variables used in an if condition***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: "too many elements in numlist": -egen anycount(), values(numlist)-** - Next by Date:
**st: re: ivreg2 results do not replicate from stata 9 to stata 11** - Previous by thread:
**st: "too many elements in numlist": -egen anycount(), values(numlist)-** - Next by thread:
**st: RE: Obtain the list of variables used in an if condition** - Index(es):

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