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

st: sample code in -heckprob-


From   "Katsuhide Isa" <[email protected]>
To   Statalist <[email protected]>
Subject   st: sample code in -heckprob-
Date   Tue, 30 Aug 2005 21:56:36 +0900

Dear Statalisters,

I'm using Stata 8.
I have a question about the sample code in -heckprob- ([G-M] 
pp.80-1). Here is an excerpt:

----------
clear 

set seed 12309
set obs 5000

gen c1 = invnorm(uniform())
gen c2 = invnorm(uniform()) 
sum c1 c2

matrix P = (1,.5\.5,1)
matrix A = cholesky(P)
local fac1 = A[2,1]
local fac2 = A[2,2]

gen u1  = c1
gen u2  = `fac1'*c1 + `fac2'*c2
summarize u1 
replace u1 = u1/r(sd) 
summarize u2 
replace u2 = u2/r(sd) 

drop c1 c2 
gen x1 = uniform()-.5 
gen x2 = uniform()+1/3
gen y1s = 0.5 + 4*x1 + u1
gen y2s = 3 - 3*x2 + .5*x1 + u2
gen y1 = (y1s>0) 
gen y2 = (y2s>0)

heckprob y1 x1, sel(y2 = x1 x2) nolog

----------
What I don't get the idea of is the matrix-processing part 
of the above code.

It looks like a symmetric positive-definite matrix is first 
geneated, then is decomposed into the product of lower triangular 
matrix and its transpose, whose [2,1] and [2,2] elements are 
used to construct correlated two (bivariate normal) error 
terms.

But I don't see why Cholesky decomposition is required here 
to create these error terms.
I'm afraid no persuasive explanations can be found in the 
manual, though it might be just a standard routine for 
programmers.

Any suggestions welcome.
Thanks in advance.

K.I.
*
*   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