Hello,

I have investigated my problem and have not been able to find a solution. I would like to calculate the standard errors of a non-linear indicator. Here are the steps that I do :
1 - Run an OLS regression.
2 - Use the estimated coefficients of the regression to construct the indicator.
3 - Make a bootstrap to calculate the standard errors.
This is the first time that I write my own program and I have a hard time getting what I want. The program works well just for 1 item between "Transport ... Other", but I can not replicate it for the whole at the same time while using the foreach command. The coefficients of the indicator do not change when I use the foreach command whereas they are different when I calculate them individually.

Here is the code I use :

global wlist logc logt A_en A_ea B_en B_ea C_en C_ea F_1524 G_2534 H_3544 I_4554

foreach var of varlist transport clothing leisure media other A_en A_ea B_en B_ea C_en C_ea F_1524 G_2534 H_3544 I_4554 E_O55{
egen m_`var'_up = mean(`var')
}

cap program drop deltaOLS
program define deltaOLS, rclass

args var transport clothing leisure media other adultg

foreach var of varlist transport clothing leisure media other {

qui reg `var' $wlist $vlist if chef ==1 & pri4 ==1, r
mat coef=e(b)

return scalar pi_up_Aen = [(_b[logt] - _b[logc]) + _b[A_en] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_Aea = [(_b[logt] - _b[logc]) + _b[A_ea] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_Ben = [(_b[logt] - _b[logc]) + _b[B_en] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_Bea = [(_b[logt] - _b[logc]) + _b[B_ea] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_Cen = [(_b[logt] - _b[logc]) + _b[C_en] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_Cea = [(_b[logt] - _b[logc]) + _b[C_ea] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_F = [(_b[logt] - _b[logc]) + _b[F_1524] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_G = [(_b[logt] - _b[logc]) + _b[G_2534] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_H = [(_b[logt] - _b[logc]) + _b[H_3544] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_I = [(_b[logt] - _b[logc]) + _b[I_4554] - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)

return scalar pi_up_J = [(_b[logt] - _b[logc]) - ///
[(_b[A_en]*m_A_en_up)+(_b[A_ea]*m_A_ea_up)+(_b[B_en]*m_B_en_up)+(_b[B_ea]*m_B_ea_up)+(_b[C_en]*m_C_en_up)+(_b[C_ea]*m_C_ea_up)+(_b[F_1524]*m_F_1524_up)+(_b[G_2534]*m_G_2534_up)+(_b[H_3544]*m_H_3544_up)+(_b[I_4554]*m_I_4554_up)]] ///
/(_b[logc]+m_`var'_up)
}

end

set seed 91857785
foreach var of varlist transport clothing leisure media other {
bootstrap r(pi_up_Aen) r(pi_up_Aea) r(pi_up_Ben) r(pi_up_Bea) r(pi_up_Cen) r(pi_up_Cea) r(pi_up_F) r(pi_up_G) r(pi_up_H) (pi_up_I) saving(.\bs_`var'_up.dta, replace) rep(2): deltaOLS `x' , vce (robust)
}


Can anyone help me ?
Thank you in advance.