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]

st: How to retrieve parameter estimates from an ML program, so they can be used in estimation of expected values, variances, etc...


From   SLG Brilleman <sam.brilleman@bristol.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: How to retrieve parameter estimates from an ML program, so they can be used in estimation of expected values, variances, etc...
Date   Mon, 29 Mar 2010 12:54:31 +0100

Hi

I have recently written a program for ml estimation using the generalized Gamma distribution. The estimation routine seems to run fine and will produce estimates of the coefficients for the linear predictor (mu), and estimates of the two shape parameters (sigma and kappa).

My problem is that I want to estimate the expected value of yi (i.e. the individual predictions) - an equation involving estimates of all three parameters (mu, sigma, kappa). I am reasonably new to STATA and cannot figure out the syntax to retrieve and store the estimates of mu, sigma, and kappa, so that I can generate the new variable yi.

I have tried 'ereturn', 'scalar' and 'gen' statements both within the program and externally after ml maximise (when outside the program I have the additional problem of distinguishing between the two shape parameters currently both _cons in the output).

Any help would be much appreciated! My code is currently along the lines of...

/* Full log-likelihood */
program ggm, eclass
	version 10
	args todo b lnf
	
	/* Define parameters of GGM */
	tempvar mu sigma kappa 		
	mleval `mu' = `b', eq(1)	
	mleval `sigma' = `b', eq(2)
	mleval `kappa' = `b', eq(3)
	
	/* Temporary variables to be used in likelihood */
	tempvar n sumlny A B
	quietly gen double `n' = _N
	quietly egen double `sumlny' = total(ln($ML_y1))
	quietly gen double `A' = abs(`kappa')^(-2)
quietly egen double `B' = total(exp((((abs(`kappa'))*(sign(`kappa'))/(`sigma'))*(ln($ML_y1)-`mu'))))

	/* Log-likelihood */
mlsum `lnf' = (`n'*(`A'-0.5)*ln(`A'))-(`n'*ln(`sigma'))-(`n'*lngamma(`A'))-`sumlny'+ ///
		((sign(`kappa')*(sqrt(`A'))/(`sigma'))*(`sumlny'-`n'*`mu'))-(`A'*`B')

	/* Some of the attempts at extracting sigma */
	scalar __sigma =_b[`sigma':_cons]
	gen __sigma =_b[`sigma':_cons]
	ereturn scalar sigma = _b[sigma:_cons]
end

Thanks,
Sam.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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