Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: eclass program based on cmp
From
Benjamin Villena <[email protected]>
To
Statalist <[email protected]>
Subject
st: eclass program based on cmp
Date
Sun, 21 Oct 2012 13:44:15 -0700 (PDT)
Dear members,
This is follow-up of a previous question to this forum. I want to construct an eclass program that estimates a multiequation model using the cmp routine (Roodman 2012). I have estimated using a multiequation model using cmp directly, but the procedure becomes numerically unstable. I figure out that by standardizing the regressors, the performance improves a lot. The problem is that I want to recover the parameters in its original scale after estimation and store them in the usual e(b), e(V) and other eclass scalars.
I posted my program at the end of this message. When tested, I got I am rookie in program writing in Stata, so I got the following message
estimates post: matrix has missing values
r(504);
Moreover, even though I get the e(b) and e(V), they do not include the re-scaling I'm trying to make.
Even though I have some experience in do-file programming, I'm a rookie on eclass programs.
Any guidance in order to solve this problems will be appreciated
Best,
Benjamin
*******************************************************************
cap program drop ecmp
program ecmp, eclass
version 11.2
syntax anything(equalok) [if] [in] [fw pw aw iw] [, *]
tokenize "`anything'", parse("()= ")
local num=1
local cvar=1
local sanyth
local listvar
local prev
while "``num''" !="" {
*Standardize variables except the dependent one - first after "(" -
local term "``num''"
if "``num''" !="(" & "``num''" !=")" & "``num''" !="=" & "`prev'" !="(" {
qui summ ``num'' `if' `in' `weight'
tempname mean``num''
sca `mean``num''' = r(mean)
tempname sd``num''
sca `sd``num''' = r(sd)
tempvar s``num''
cap gen `s``num''' = (``num''-r(mean))/r(sd)
local vv_`cvar' ``num''
local ++cvar
local term "`s``num'''"
local listvar `listvar' ``num''
}
local sanyth "`sanyth' `term'"
local prev "``num''"
local ++num
}
di "`listvar'"
di "`sanyth'"
tempname MEAN
matrix `MEAN'=J(`cvar',1,0)
tempname SD
matrix `SD'=`MEAN'
local k=1
foreach vv in `listvar'{
matrix `MEAN'[`k',1]=`mean`vv''
matrix `SD'[`k',1]=`sd`vv''
local ++k
}
cmp `sanyth' `if' `in' `weigth' `exp', `options'
tempname newb newV oldll oldN newll newN
matrix `newb' = e(b)
matrix `newV' = e(V)
forv k=1/`cvar'{
matrix `newb'[1,`k'] = `newb'[1,`k']/`SD'[`k',1]
forv j=1/`cvar'{
matrix `newV'[`k',`j'] = `newV'[`k',`j']/`SD'[`k',1]/`SD'[`j',1]
}
}
ereturn post `newb' `newV'
end
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/