Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Goodness of fit of -intreg depvar1 depvar2 indepvars, het(subset_of_indepvars) robust-


From   "Renzo Comolli" <[email protected]>
To   <[email protected]>
Subject   st: Goodness of fit of -intreg depvar1 depvar2 indepvars, het(subset_of_indepvars) robust-
Date   Sun, 11 Apr 2004 18:03:13 -0400

I would like to have measures of goodness of fit for 
intreg  depvar1 depvar2 indepvars, het(subset_of_indepvars) robust
constraints(1)

The measure I would really like is variance of predicted y, but I would
settle for other measures too.

I can't use -fitstat- because it was written for the Stata 7 version of
-intreg-.
I hacked the code of -fitstat- enough to make it work for Stata 8 version of
-intereg-, but it does not work if I specify the option -, het()- and I
don't understand the code enough to hack it further. 
(I wrote to Mr. Long months ago, so that is not an option)

I post here my hacked version of the code to compute variance of predicted
y, but fails (as said) if the -, het()- option is specified.

Any help would be appreciated.
Best Regards.
Renzo Comolli




capture program drop vystar
program define vystar, rclass
    version 6.0

    tempname n_obs n_parm  b v_ystar v v_y v_x v_e factor bnocon 

    mat `b' = get(_b)
    local depv `e(depvar)'

*-> get information from last model estimated
    mat `v_e' = J(1,1,1)
    sca `n_obs' = e(N)

*-> compute numbers of variables and parameters
    sca  `n_parm' = colsof(`b')
    local n_rhs = `n_parm' - 2  /*  for var(e) */ 
 
    local varlist : colnames(`b')
    parse "`varlist'", parse (" ")

    * 2/11/00
    * to deal with rhsnam gt 80 characters, can't use string functions
    local rhsnam ""
    local i 1
    while "``i''"!= "" {
            if "``i''"!="_cons" & "``i''"!="_se" { local rhsnam "`rhsnam'
``i''" }
            local i = `i' + 1
    }

*-> compute Var(y*) using cov_x

        scalar `factor' = 1/(`n_obs'-1)
        quietly mat accum `v_x' = `depv' `rhsnam' if e(sample), deviations
noconstant
        scalar `v_y' = `factor' * `v_x'[1,1] /* sum y/(n-1) */
        mat `v_x' = `factor' * `v_x'[2...,2...]  /* cov matrix of rhs vars
*/
        mat `v_x' = `v_x'[2...,2...] 
        mat `bnocon' = `b'[1,1..`n_rhs'] /* trim off _con */
        mat `v' = `bnocon' * `v_x' * `bnocon''
        mat `v_e'[1,1] = e(sigma)*e(sigma) 
        mat `v' = `v' + `v_e'
        scalar `v_ystar' = `v'[1,1]
	display "Variance of Fitted y* :" " " `v_ystar'
	return scalar v_ystar = `v_ystar'

end


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index