/****I am trying to write a wrapper program using GMM. The program more or less looks like this:****/
program define svywt
syntax varlist, wtvar(varlist) //syntax to include two separate variable lists//
gettoken depvar indepvars : varlist //parsing depedent var and independent vars from first varlist//
_fv_check_depvar `depvar'
local first(first: `:word 1 of `wtvar''/(1+{xb: `wtvar'})) //first equation in the interactive version of GMM (no instrument)//
local second(second: `:word 2 of `wtvar''/(1+{xb: })) //second equation in the interactive version of GMM (no instrument)//
local third(third
`depvar' - ({`depvar': `indepvars' _cons}))/ (1+{xb: })) //third equation in the interactive version of GMM//
local third_inst instruments(third: `indepvars') //instruments for third equation//
gmm `first' `second' `third', `third_inst' onestep winitial(unadjusted, independent) //GMM in one step//
end
sysuse auto, clear
egen y = mean(price)
gen price_1 = price -y
egen x = mean(mpg)
gen mpg_1=mpg-x
svywt price weight mpg, wtvar(price_1 mpg_1) //estimation using defined program//
/****While I'm using the above semi-automated code, the program works. However, I want to make this program fully automated e.g., I want to use a loop so that I can perform GMM avoiding writing as many moments as "wtvar" manually e.g., first and second in this case. I was trying to wite in the following way, but I think there is something wrong in my logic because I am unable to include all equations within my GMM:****/
clear all
program define svywt
syntax varlist, wtvar(varlist)
gettoken depvar indepvars : varlist
_fv_check_depvar `depvar'
local p: word count `wtvar'
forvalues i=1(1)`p'{
local first_`i'(first_`i': `:word `i' of `wtvar''/(1+ {xb: `wtvar'})) //first and second equations in the interactive version of GMM (no instrument)//
local third(third
`depvar' - ({`depvar': `indepvars' _cons}))/ (1+ {xb: })) //third equation in the interactive version of GMM//
local third_inst instruments(third: `indepvars')
gmm `first_`i'' `third', `third_inst' onestep winitial(unadjusted, independent)
}
end
//****In the above case, I able to include only four equations out of five equations. If I have "p" equations for "wtvar" and a final equation for first "varlist", I want to incorporate p equations through a loop and final equation manually in GMM.****/
sysuse auto, clear
egen y = mean(price)
gen price_1 = price -y
egen x = mean(mpg)
gen mpg_1=mpg-x
svywt price weight mpg, wtvar(price_1 mpg_1)
I do appreciate your kind help to overcome this problem.
Sincerely,
Rabiul
program define svywt
syntax varlist, wtvar(varlist) //syntax to include two separate variable lists//
gettoken depvar indepvars : varlist //parsing depedent var and independent vars from first varlist//
_fv_check_depvar `depvar'
local first(first: `:word 1 of `wtvar''/(1+{xb: `wtvar'})) //first equation in the interactive version of GMM (no instrument)//
local second(second: `:word 2 of `wtvar''/(1+{xb: })) //second equation in the interactive version of GMM (no instrument)//
local third(third

local third_inst instruments(third: `indepvars') //instruments for third equation//
gmm `first' `second' `third', `third_inst' onestep winitial(unadjusted, independent) //GMM in one step//
end
sysuse auto, clear
egen y = mean(price)
gen price_1 = price -y
egen x = mean(mpg)
gen mpg_1=mpg-x
svywt price weight mpg, wtvar(price_1 mpg_1) //estimation using defined program//
/****While I'm using the above semi-automated code, the program works. However, I want to make this program fully automated e.g., I want to use a loop so that I can perform GMM avoiding writing as many moments as "wtvar" manually e.g., first and second in this case. I was trying to wite in the following way, but I think there is something wrong in my logic because I am unable to include all equations within my GMM:****/
clear all
program define svywt
syntax varlist, wtvar(varlist)
gettoken depvar indepvars : varlist
_fv_check_depvar `depvar'
local p: word count `wtvar'
forvalues i=1(1)`p'{
local first_`i'(first_`i': `:word `i' of `wtvar''/(1+ {xb: `wtvar'})) //first and second equations in the interactive version of GMM (no instrument)//
local third(third

local third_inst instruments(third: `indepvars')
gmm `first_`i'' `third', `third_inst' onestep winitial(unadjusted, independent)
}
end
//****In the above case, I able to include only four equations out of five equations. If I have "p" equations for "wtvar" and a final equation for first "varlist", I want to incorporate p equations through a loop and final equation manually in GMM.****/
sysuse auto, clear
egen y = mean(price)
gen price_1 = price -y
egen x = mean(mpg)
gen mpg_1=mpg-x
svywt price weight mpg, wtvar(price_1 mpg_1)
I do appreciate your kind help to overcome this problem.
Sincerely,
Rabiul