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

st: matrices and linear transformations

From   "Paulo Regis" <>
Subject   st: matrices and linear transformations
Date   Wed, 4 Jun 2008 17:17:05 +0100

Hello all,

I am having some problems creating weighted average variables. I
usually work with gauss and I would use matrix operations to do this.
In Stata, a similar procedure may be

mkmat x1-x5, mat(XMAT)
mkmat m1-m10, mat(MMAT)
svmat WXMAT, names(mx)

In this example, you have five variables (x1-x5) with 10 observations
(_N=10) and ten variables (m1-m10) that are the weights. You end up
with five new variables (mx1-mx5) which are the weigthed average of
the original x variables. Alternatively, I have tried to use the
command egen (using the function total()), following this old tread

I modified the file "_gmean.ado" to introduce a weighting variable.
Working out the code, you can obtain mx1-mx5, however, you have to
modify the code for each variable.

The problem of the first alternative is that it takes a lot  of time.
This may become especially problematic if the number of observation is
large enough while the second alternative is not a "general" solution
(also, there are some efficiency problems since it creates several
unnecessary variables). There is any other alternative to do this?

Thank you,

*   For searches and help try:

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