[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> |

Subject |
st: RE: Re: How to refer to scalars with a wildcard |

Date |
Mon, 12 Apr 2004 19:49:53 +0100 |

Correct. Sorry about that. Nick n.j.cox@durham.ac.uk > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Friedrich > Huebler > Sent: 12 April 2004 19:42 > To: statalist@hsphsun2.harvard.edu > Subject: st: Re: How to refer to scalars with a wildcard > > > Nick, > > Thank you, your loop works with one correction: the -else- line does > not need a comma. > > else local ages "`ages'age`i'" > > Friedrich Huebler > > --- Nick Cox <n.j.cox@durham.ac.uk> wrote: > > I'd modify your -forval- loop > > and build up a list of names one > > by one (add semi-colons as desired) > > > > forvalues i = `start'/`end' { > > sum income if age==(`i'+startage-1) > > scalar age`i' = r(mean) > > if `i' < `end' local ages "`ages'age`i'," > > else local ages "`ages',age`i'" > > } > > > > Then > > > > matrix data = startage,endage,male,female,`ages'; > > > > Nick > > n.j.cox@durham.ac.uk > > > > Incidentally, it looks as if your -summarize- should > > be done ", meanonly". > > > > Friedrich Huebler > > > > > > I work with household survey data and would like to create > > summary > > > statistics disaggregated by gender, age and other > > characteristics. In > > > my do-file the summary statistics are stored as scalars and then > > > converted to a matrix. I encountered a problem with the > > disggregation > > > by age because I use varying age ranges. Let's assume I want to > > > summarize income by gender and age (for ages 20-24 in this case) > > with > > > the following data. > > > > > > age male income > > > 20 1 6 > > > 21 1 7 > > > 22 0 5 > > > 23 0 9 > > > 24 1 6 > > > > > > * Set start and end age (NOTE: THE AGES VARY); > > > scalar startage = 20; > > > scalar endage = 24; > > > * Summarize income by gender; > > > sum income if male==1; > > > scalar male = r(mean); > > > sum income if male==0; > > > scalar female = r(mean); > > > * Summarize income by age; > > > local start = 1; > > > local end = (endage - startage + 1); > > > forvalues i = `start'/`end' {; > > > sum income if age==(`i'+startage-1); > > > scalar age`i' = r(mean); > > > }; > > > > > > The problem is in the following step. Because I use varying age > > > ranges I cannot list all age variables individually (age1, age2, > > > age3, ...) but want to refer to them with a wildcard character. > > > > > > drop _all; > > > matrix data = startage,endage,male,female,age*; > > > svmat data; > > > > > > This leads to this error message: > > > > > > age* not found > > > r(111); > > > > > > Can the matrix be created without listing all scalars > > individually? > > __________________________________ > Do you Yahoo!? > Yahoo! Tax Center - File online by April 15th > http://taxes.yahoo.com/filing.html > * > * 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/ > * * 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/

- Prev by Date:
**Re: st: Adding a scheme to Graph Preferences** - Next by Date:
**st: Problem outregging GLLAMM results** - Previous by thread:
**st: SECOND announcement of 3rd NASUG** - Next by thread:
**st: Problem outregging GLLAMM results** - Index(es):

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