Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: aggregate means of 113 grouped variables


From   Dietrich Drüner <dietrich.druener@web.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: aggregate means of 113 grouped variables
Date   Thu, 6 May 2004 11:06:29 +0200

Dear statalisters,

my data set contains 113 variables that belong to 62 cases. There are 1 to 5
variables per case.
I need to calculate the mean of the means of these 1 to 5 variables for each
of my 62 cases.

-----------------------------------------
A possible code for one case with 3 variables looks like this:

sum sd0032i1
local x=r(mean)
sum sd0032i3
local y=r(mean)
sum sd0032i4
local z=r(mean)

gen msd0032=(`x’+`y’+`z’)/3

--------------------------------------

The 3rd to 6th letter of the variable names is identical for the variables
of each case, the last letter distinguishes the 1 to 5 variables with an
ascending order but unfortunately sometimes with "gaps" like in the case
above.

My problem is: how can I generalise this - or an equivalent - code to be
repeated 62 times with a varying number of variables?


I would be grateful for hints to solve this problem!

Dietrich.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dietrich Drüner
Schneckenburgstr. 24
D - 78467 Konstanz

Tel. (+49) - 7531 - 698003
Fax (+49) - 1212 - 522970813
Mob.(Inland): (+49) - 177 - 6334099
Mob.(Ausland):(+49) - 162 - 7679952

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index