[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: How to refer to scalars with a wildcard |

Date |
Mon, 12 Apr 2004 18:39:58 +0100 |

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? * * 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**:**st: Re: How to refer to scalars with a wildcard***From:*Friedrich Huebler <huebler@rocketmail.com>

- Prev by Date:
**st: please unsubscribe me from the list** - Next by Date:
**Re: st: Re: statsby and xtreg** - Previous by thread:
**st: RE: Goodness of fit of -intreg depvar1 depvar2 indepvars, het(subset_of_indepvars) robust-** - Next by thread:
**st: Re: How to refer to scalars with a wildcard** - Index(es):

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