Statalist The Stata Listserver


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

Re: st: -collapse- and variable names


From   John Fulton <[email protected]>
To   [email protected]
Subject   Re: st: -collapse- and variable names
Date   Sat, 27 Jan 2007 15:14:49 -0500

Try foreach creating a new set of variables with the same values as the old variables.
foreach var of newlist string1-string50 {
2. gen newvar_`var' = varname_`var'
3. }


Herve STOLOWY wrote:

Dear Statalisters:

I have a data set with approx. 50 variables. Their name starts with the same prefix: varname_string1, varname_string2... varname_string50. I would like to get the count and mean with a collapse. For the moment, I can get each stat separately by doing:

collapse (mean) varname*
or
collapse (count) varname*

Is there a way to get the two stats at the same time? I checked the help file of -collapse- and I know that I need to create a new variable name for the second variable but, given the number of variables, I always get some error message when I do, for example:

collapse (count) varname* (mean) mean_varname* = varname*

I guess I can do it separately and then merge the two files but this is not very elegant.

Best regards

Herv� Stolowy



***********************************************************
Professeur/Professor
HEC Paris
D�partement Comptabilit� Contr�le de gestion / Dept of Accounting and Management Control
1, rue de la Liberation
78351 - Jouy-en-Josas
France
Tel: +33 1 39 67 94 42 - Fax: +33 1 39 67 70 86
mail: stolowy at hec dot fr
web: http://studies.hec.fr/web/stolowy

*
* 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/



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