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

st: Loop for Shapley Decomposition sub-routine


From   Ramani Gunatilaka <[email protected]>
To   [email protected]
Subject   st: Loop for Shapley Decomposition sub-routine
Date   Sun, 25 Jan 2004 08:56:28 +0000

Hi all,
I am trying to apply the Shapley decomposition method to household consumption data.
I am wondering if there is a short cut to do the following subroutine.

Consumption data is x, and assume there are 4 explanatory variables, var1-var4.

I have performed the following:

regress x var1 var2 var3 var4

saved the betas as B1, B2 etc. upto B5 (coeff on the constant) and generated them as variables alongside var1 var2 etc.

I next need to generate means of variables, vbar1, vbar2, and generate new consumption variables x1 x2 x3 x4 as follows.

Using a loop,

local i=$j/*where $j is total no of vars, that is 4*/
while `i'>=1{
qui sum var`i'
qui gen vbar`i'=r(mean)
qui gen XXXXXX/*see below*/
local i =`i'-1
}

The XXXXXX part has to read as follows if i=4

x4=exp((B1*var1)+(B2*var2)+(B3*var3)+(B4*vbar4) +(B($j+1))/*constant*/

if i=3, then XXXX must read,

x3=exp((B1*var1)+(B2*var2)+(B3*vbar3)+(B4*var4) +(B($j+1))/*constant*/

if i=2, then XXXXX goes,
x2=exp((B1*var1)+(B2*vbar2)+(B3*var3)+(B4*var4) +(B($j+1))/*constant*/

etc. 

Can anyone please suggest how I may write an expression for XXXXX which includes all the above possibilities, depending on the value that `i' takes and even if I have 25 variables?

Thanks so much,
Ramani
*
*   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