[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"b. water" <barleywater@hotmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: indirect evaluation of variables |

Date |
Mon, 31 Mar 2003 11:55:39 +0000 |

dear nick,

tried to run your macro:

. gen blob = .

(4 missing values generated)

. forval i = 1 / `= _N' {

2. replace blob = bl`= `bleen'[`i']' in `i'

3. }

bl1 not found

r(111);

end of do-file

r(111);

but that was the result.

however, gen blob = cond(bleen == "ing", bling, blam) worked.

quite curious as to why the macro did not work but i am ok with the alternative.

thanks,

bw

From: "Nick Cox" <n.j.cox@durham.ac.uk> Reply-To: statalist@hsphsun2.harvard.edu To: <statalist@hsphsun2.harvard.edu> Subject: st: RE: indirect evaluation of variables Date: Mon, 31 Mar 2003 11:11:19 +0100 Bill Rising > I've run into a situation where I'd like to build an > expression which > contains different variables depending on the observation. > Now, this > could be done by nesting a series of -cond()-s, though it > would be a bit > complex (and hard to generalize). > > Is there some way to use variables a pointers (use indirect > evaluation of > the variables)? For example suppose that there were three variables: > > bleen bling blam > ing 1 11 > am 2 12 > ing 3 13 > ing 4 14 > > I'd like to be able to have > > gen blob = eval("bl"+bleen), so that the dataset would then be > > bleen bling blam blob > ing 1 11 1 > am 2 12 12 > ing 3 13 3 > ing 4 14 4 > > where the (non-existant) -eval()- function takes its string > argument and > interprets it as the name of a variable. > > I vaguely recall being stumped by this once in the past, > and know that > I'm stumped once again. Any tips would be much appreciated, > even negative > ones. As Bill says, there is a -cond()- solution: gen blob = cond(bleen == "ing", bling, blam) Macros could also be used with the downside of a great loss in speed: gen blob = . forval i = 1 / `= _N' { replace blob = bl`= `bleen'[`i']' in `i' } Nick n.j.cox@durham.ac.uk * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

_________________________________________________________________

Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail

*

* For searches and help try:

* http://www.stata.com/support/faqs/res/findit.html

* http://www.stata.com/support/statalist/faq

* http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**RE: st: RE: indirect evaluation of variables***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: indirect evaluation of variables** - Next by Date:
**RE: st: RE: indirect evaluation of variables** - Previous by thread:
**st: Re: statalist-digest V4 #1203** - Next by thread:
**RE: st: RE: indirect evaluation of variables** - Index(es):

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