Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Trouble using - estimates store- (new inquiry)


From   Federico Belotti <f.belotti@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Trouble using - estimates store- (new inquiry)
Date   Mon, 20 May 2013 12:56:06 +0200

Dear Benjamin,

maybe there is something specific in your code that does not follow standard Stata syntax.
I cannot provide a customized solution without taking a look at your code.
Anyways, below a working example which should replicate your framework.

HTH,
Federico

cap prog drop myprog
program myprog, eclass byable(onecall) 
	
version 11.2
	if replay() {
	if _by() {
		error 190
	}
	_coef_table `0'
	exit
}
syntax varlist [if] [in] 
gettoken lhs rhs: varlist
marksample touse
tempvar l`lhs'
gen `l`lhs'' = ln(`lhs') if `touse'
foreach v of local rhs {
	tempvar l`v'
	gen `l`v'' = ln(`v') if `touse'
	local transfrhs "`transfrhs' `l`v''"
}
cap cmp (`l`lhs'' = `transfrhs') if `touse', indicators(1) quietly
if _rc {
	di as err "cmp error"
	error 198
}
tempname _b _V
mat `_b' = e(b)
local eqname: coleq `_b'
local eqname = subinstr("`eqname'", "`l`lhs''", "`lhs'",.)
mat `_V' = e(V)
mat colnames `_b' = `rhs' _cons
mat coleq `_b' = `eqname'
mat colnames `_V' = `rhs' _cons
mat rownames `_V' = `rhs' _cons
mat coleq `_V' = `eqname'
mat roweq `_V' = `eqname'
eret post `_b' `_V', obs(`e(N)') esample(`touse') depname(`lhs')
eret local cmd myprog
_coef_table 
end

sysuse auto, clear
myprog price mpg
eret li
bootstrap, r(5): myprog price mpg


On May 20, 2013, at 7:07 AM, Benjamin Villena wrote:

> Dear Federico,
> I appreciate your help. 
> What you suggested worked, but it generated an unexpected side-effect
> 
> When I tried to use my code using bootstrap, I got the following error 
> something required
> r(100)
> 
> Since this was the only change I made, I tried deleting the line you suggested in my ado file, and my bootstrap estimation worked!
> I could even store my estimates using  -estimates store basemodel-
>  Looking at the ereturn list, I realized that the bootstrap assigns e(cmd) : "bootstrap"
> It seems that there is a conflict using 
> -ereturn local cmd "thenameofyouradofile"- when my ado file is used for bootstrap.
> Many commands attach their names to e(cmd), with no conflict if they are bootstrapped... I do not know how to do this.
> How can I set this right so I can store estimates when I use my ado file both (i) in a regular way and (ii) in a bootstrap?
> 
> Thanks
> 
> 
> 
>> ________________________________
>> From: Federico Belotti <f.belotti@gmail.com>
>> To: statalist@hsphsun2.harvard.edu 
>> Sent: Sunday, May 19, 2013 12:22 PM
>> Subject: Re: st: Trouble using - estimates store-
>> 
>> 
>> Try to store the command name, that is include in your ado file
>> 
>> ereturn local cmd "thenameofyouradofile"
>> 
>> this should be enough to ensure that -estimates store- works.
>> 
>> HTH,
>> Federico
>> 
>> On May 19, 2013, at 12:01 AM, Benjamin Villena wrote:
>> 
>>> Dear Statalist members,
>>> 
>>> I wrote an ado file that does the following:
>>> (1) It transforms variables in a particular way, say compute X1=G(X) where X is the original variable
>>> (2) It estimates a model using a user-written package (cmp) with the transformed variables X1
>>> The code works fine. It stores coefficients and variance matrix into e(b) and e(V)... ereturn list shows the estimated values are preserved. But if I try -estimates store equation1- I get the following error
>>> 
>>> last estimation results not found, nothing to store
>>> r(301)
>>> 
>>> I do not get it, how does Stata recognize there are estimates in memory? I believed that having e(b) and e(V) would be enough, but apparently is not. What am I missing here?
>>> 
>>> Thanks
>>> 
>>> Benjamin 
>>> 
>>> *
>>> *   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/
>> 
>> -- 
>> Federico Belotti, PhD
>> Research Fellow
>> Centre for Economics and International Studies
>> University of Rome Tor Vergata
>> tel/fax: +39 06 7259 5627
>> e-mail: federico.belotti@uniroma2.it
>> web: http://www.econometrics.it
>> 
>> 
>> *
>> *   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/
>> 
>> 
>> 
> 
> *
> *   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/

-- 
Federico Belotti, PhD
Research Fellow
Centre for Economics and International Studies
University of Rome Tor Vergata
tel/fax: +39 06 7259 5627
e-mail: federico.belotti@uniroma2.it
web: http://www.econometrics.it


*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index