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 on April 23, and its replacement, is already up and running.

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

st: simluated errors in multivariate probit model

From   Zhi Su <>
To   statalist <>
Subject   st: simluated errors in multivariate probit model
Date   Tue, 7 Jun 2011 16:55:54 -0400

*estimate the multivariate probit model using mvprobit,`basic' is a set of X
mvprobit (T1=`basic') (T2=`basic') (T3=`basic') (T4=`basic'),robust

*save the xb
mvppred xbm,xb

*start mata workplace

/*number of repetions*/

/*number of observations*/

/*I get variance and covariance matrix from MVProbit
/*I input the values from results of MVPROBIT*/
/*V has values of 1 on the leading diagonal and correlations ρjk = ρkj
as off-diagonal elements*/


/*build a column vector and fill in values of means of simulated error
terms for each observation, which is calculated by the following

/*build a matrix and fill in values of means of simulated error terms
for each observation*/

/* Loop through the simulations for 677 obsertions used in calculation
of mvprobit*/
for(k=1;k<=O;k++) {

/*Multiple draws from multivariate normal distribution with variance
and covariance V*/
/*the matrix is drawn from N(0,V)*/

/*create a copy of data for each observations (from 1 to 677) into
mata workplace*/

XBM=st_data(k,("xbm1", "xbm2", "xbm3","xbm4"))

/*generate simulated latent Y matrix*/

/* make an N by 4 matrix of 1 to prepare for a matrix of Y_si index*/
Y_in= J(N, 4, 1)

/* loop through the rows and columns of the matrix Y_si, setting the
value in a cell of Y_in*/
/* equal to 0 if Y_si is less than 0*/

for(i = 1; i <= rows(Y_si); i++) {
      for(j = 1; j<=cols(Y_si); j++) {
         	if (Y_si[i,j]<0) {

/* make an N by 1 matrix of 0 to prepare for Y_in matrix selection rule*/
D= J(N,1, 0)

/*loop through each row of Y_in and compare it with actual Y*/
/*set corresponding row of D to 1 if two rows are equal*/

for(i = 1; i <= rows(Y_si); i++) {
   if  (Y_in[i,.]==Y) {

/* only simulated error U that satisfy Y_in=actual Y are obtained,
when rows of D==1*/
U_s=select(U, D:==1)

/*column means of simulated error matrix U_s*/

/*fill in rows of M_m*/

/*store the calculated values in the Stata variable "u*"*/
st_store((1,rows(M_m)),"u1", M_m[.,1])
st_store((1,rows(M_m)),"u2", M_m[.,2])
st_store((1,rows(M_m)),"u3", M_m[.,3])
st_store((1,rows(M_m)),"u4", M_m[.,4])

/*store the calculated values in the Stata variable "res_si"*/

/*end mata worksplace*/

*I standardize u1 u2 u3 u4

egen Su1=std(u1)
egen Su2=std(u2)
egen Su3=std(u3)
egen Su4=std(u4)

corrmat Su1 Su2 Su3 Su4

               Su1            Su2            Su3        Su4
Su1          1
Su2  .81469367          1
Su3  .77865427  .62243427  .99999999
Su4  .90029139  .65351567  .66685678          1

The varriance is different from the original variance and covariance
matrix "V" I set, why?
            u1             u2                u3         u4
u1         1
u2 0.6524083            1
u3 0.6021572    0.4410809          1
u4 0.7241811    0.421958   0.4515065       1

Are there any mistakes in the codes?
Thank you!

Zhi Su
348 Holmes Hall
Northeastern University
360 Huntington Avenue
Boston, MA 02115

*   For searches and help try:

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