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

From |
Jeph Herrin <jeph.herrin@yale.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: -varlist- using char[]? |

Date |
Fri, 14 Nov 2008 08:07:29 -0500 |

Thanks for the tip about -ds-, that will at least answer my first question in the something close to affirmative. And yes, I did simplify in my examples, because I was too lazy to check my code. Similarly (per Nick's comment), I know that -summarize if <cond>- was completely out of line, but thought it was worth a thousand words of trying explain what I wanted to do. Had never noticed that feature of -ds-, quite useful. Though would be nice it was extending to matching particular char values. Eg, . ds, has(char scale KCCQ) thanks, Jeph Johannes Geyer wrote: >> This has been helpful in a lot of programming contexts. >> For instance, I currently pull out the variables that form >> the KCCQ survey scale by looping over ALL the variables >> >> foreach V of _all { >> local scale = V[scale] >> if "`scale'"=="KCCQ" { >> ... >> } >> } >> > > I have a question related to your code: > > local scale = V[scale] > > does this work or did you simplify? > > I get an error message, Stata does not know what > "scale" is, so I have to write > > local scale = "`V[scale]'" > > furthermore "V" is a local, the code would be: > > local scale = "``V'[scale]'" > > You could also use -ds-: > > ds, has(char scale) > > then the code would read: > > /***************/ > qui ds, has(char scale) > foreach v of varlist `r(varlist)' { > > local scale = "``v'[scale]'" > if "`scale'"=="KCCQ" { > ... > } > } > /***************/ > > Johannes > > > * > * 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/

- Prev by Date:
**Re: st: Mata question** - Next by Date:
**Re: Re: Re: st: more fancy NP++ editor** - Previous by thread:
**st: RE: -varlist- using char[]?** - Next by thread:
**st: Dropping min of two consecutive observations** - Index(es):

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