Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Nick Cox <n.j.cox@durham.ac.uk> |

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

Subject |
RE: st: RE: looping up to a local macro |

Date |
Thu, 23 Jun 2011 16:40:10 +0100 |

You aren't obviously misunderstanding macros; you just don't need them as much as you think. There is no reference to -letter_sound- in the code segment you cite, so there is something that you have not explained. That said, you are missing some tricks. If you want a row mean, you can use egen ... = rowmean(letter*) so that you do not need * to know how many variables are covered by the wildcard letter* * to calculate totals and then counts for the row means. Nick n.j.cox@durham.ac.uk Michael Costello Wow, this became a much bigger thing than I was anticipating! Thanks for all the interest though. I guess I'm wondering if I am thinking of the local macro correctly, in that it's a kind of proxy for some value (in my case 50, 100, etc) which can have operations done unto it, or if it's something else that I don't understand. I manage ~30 databases. Most of them need the same bits of code run on them, but each has a different number of variables upon which that code must be run. For example: Database 1 has variables letter1, letter2, letter3, . . . , letter100 Database 2 has variables letter1, letter2, letter3, . . . , letter50 I would like to create this "master cleaning file" which, after establishing a local macro value of either 50 or 100, would do the following: **Section: Letter Names** egen letter_score2=rowtotal(letter1-letter`letters'), missing egen letter_attempted=rownonmiss(letter1-letter`letters') gen letter_score_pcnt=letter_score/`letters' gen letter_score_zero= (letter_score==0) if letter_score<. gen letter_attempted_pcnt=letter_score/letter_attempted gen clpm=round(letter_score/(1-(letter_time_remain/60))) But the error I'm getting is: "letter_sound ambiguous abbreviation" for the first line of the code Sarah, the error i'm getting when I try to run a loop is "invalid syntax" forvalues i = 1(1)`letters' { quietly: rename letter0`i' letter`i' quietly: recode letter`i' (9=.) (2=1) (1=0) * more lines of code here } invalid syntax * * 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: looping up to a local macro***From:*Michael Costello <michaelavcostello@gmail.com>

**st: RE: looping up to a local macro***From:*"Sarah Edgington" <sedging@ucla.edu>

**Re: st: RE: looping up to a local macro***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: RE: looping up to a local macro***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: RE: looping up to a local macro***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: RE: looping up to a local macro***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: RE: looping up to a local macro***From:*Michael Costello <michaelavcostello@gmail.com>

- Prev by Date:
**Re: st: deriving the variance-covariance matrix from point estimates and standard errors** - Next by Date:
**RE: st: stata files in linux** - Previous by thread:
**Re: st: RE: looping up to a local macro** - Next by thread:
**RE: st: RE: looping up to a local macro** - Index(es):