. Hi Stata masters!
I generated simulation data using covariance matrix.
I specified all the error variances as 1 in the covariance matrix as follows (diagonal numbers are all 1).
Because I also specified my true model by setting up the values of beta slopes, the variability of Y should be dependent on the only error term.
(In other words, in the equation y=0.1+0.6*d+0.6*w1+0.6*w2+0.6*w3+0.6*w4+0.6*w5+0.6 *w6+0.6*w7+0.6*w8+0.6*w9+0.6*w10+0.6*w11+0.6*w12+0 .6*w13+0.6*w14+0.6*w15+0.6*w16+u, every term is actually a constant because I defined the numbers, except for the error (u). So the variance of Y is the same as that of error).
However when I doublecked the descriptive statistics using the code "sum", the standard deviation of Y turned out as approximately 2 in the descriptive statistics table (actually 2.58 but when I run it again, it generated 2.07 something like that. I think the more covariates are the sd of Y becomes bigger and bigger and it is not close to be 1 as specified earlier in the covariance matrix).
Why did Stata generate wrong descriptive statistics? Is this because Stata miscalcuated the sd of Y, or is this because my syntax is something wrong ? Why isn't the covariance matrix matched with the descriptive statistics in terms Standard Deviation of Y?
The following syntax is what I made and would you please let me know what I should do in order to match the diagonal number 1 in the covariance matrix with the SD of Y in the descriptive statistics?
******************Simulation Codes ************************************
.*define covariance matrix
mat P = (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1)
*Draw from normal dist.
drawnorm x u w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16, n(4000) cov(P)
*Define treatment variable
generate d=(x>0)
*define outcome variable
generate y=0.1+0.6*d+0.6*w1+0.6*w2+0.6*w3+0.6*w4+0.6*w5+0.6 *w6+0.6*w7+0.6*w8+0.6*w9+0.6*w10+0.6*w11+0.6*w12+0 .6*w13+0.6*w14+0.6*w15+0.6*w16+u
*save dataset
save decideK16,replace
*Model decideK16 descriptive statistcs to check SD(Y) and SD(D)*
use decideK16,clear
sum y d w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16
. sum y d w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
y | 4,000 .4063912 2.583068 -8.888543 11.30081
d | 4,000 .4905 .4999722 0 1
w1 | 4,000 .0130231 .9805118 -3.231501 3.674521
w2 | 4,000 .0148694 .9850495 -4.455201 3.480071
w3 | 4,000 .0190679 1.015951 -3.161212 3.477742
-------------+---------------------------------------------------------
w4 | 4,000 -.0083475 1.020264 -3.481928 3.343177
w5 | 4,000 .00874 1.003124 -4.002687 3.944189
w6 | 4,000 .0016545 .9941556 -3.615002 3.591007
w7 | 4,000 .0006976 1.01449 -3.297943 3.256187
w8 | 4,000 -.0037587 1.014113 -3.831774 3.498365
-------------+---------------------------------------------------------
w9 | 4,000 -.0095989 1.028091 -3.08722 3.859863
w10 | 4,000 .0187556 1.006128 -3.444188 3.649128
w11 | 4,000 -.002984 .9957664 -3.700773 3.406081
w12 | 4,000 .0078398 1.018744 -3.593562 4.082495
w13 | 4,000 -.0156626 1.010529 -3.729325 3.57018
-------------+---------------------------------------------------------
w14 | 4,000 .001853 1.006388 -3.269533 3.674261
w15 | 4,000 -.0226012 1.004162 -3.367424 3.241826
w16 | 4,000 -.0289284 .9867342 -3.406581 4.05419
.
end of do-file
I generated simulation data using covariance matrix.
I specified all the error variances as 1 in the covariance matrix as follows (diagonal numbers are all 1).
Because I also specified my true model by setting up the values of beta slopes, the variability of Y should be dependent on the only error term.
(In other words, in the equation y=0.1+0.6*d+0.6*w1+0.6*w2+0.6*w3+0.6*w4+0.6*w5+0.6 *w6+0.6*w7+0.6*w8+0.6*w9+0.6*w10+0.6*w11+0.6*w12+0 .6*w13+0.6*w14+0.6*w15+0.6*w16+u, every term is actually a constant because I defined the numbers, except for the error (u). So the variance of Y is the same as that of error).
However when I doublecked the descriptive statistics using the code "sum", the standard deviation of Y turned out as approximately 2 in the descriptive statistics table (actually 2.58 but when I run it again, it generated 2.07 something like that. I think the more covariates are the sd of Y becomes bigger and bigger and it is not close to be 1 as specified earlier in the covariance matrix).
Why did Stata generate wrong descriptive statistics? Is this because Stata miscalcuated the sd of Y, or is this because my syntax is something wrong ? Why isn't the covariance matrix matched with the descriptive statistics in terms Standard Deviation of Y?
The following syntax is what I made and would you please let me know what I should do in order to match the diagonal number 1 in the covariance matrix with the SD of Y in the descriptive statistics?
******************Simulation Codes ************************************
.*define covariance matrix
mat P = (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0)
matrix P = P\ (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1)
*Draw from normal dist.
drawnorm x u w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16, n(4000) cov(P)
*Define treatment variable
generate d=(x>0)
*define outcome variable
generate y=0.1+0.6*d+0.6*w1+0.6*w2+0.6*w3+0.6*w4+0.6*w5+0.6 *w6+0.6*w7+0.6*w8+0.6*w9+0.6*w10+0.6*w11+0.6*w12+0 .6*w13+0.6*w14+0.6*w15+0.6*w16+u
*save dataset
save decideK16,replace
*Model decideK16 descriptive statistcs to check SD(Y) and SD(D)*
use decideK16,clear
sum y d w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16
. sum y d w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 w16
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
y | 4,000 .4063912 2.583068 -8.888543 11.30081
d | 4,000 .4905 .4999722 0 1
w1 | 4,000 .0130231 .9805118 -3.231501 3.674521
w2 | 4,000 .0148694 .9850495 -4.455201 3.480071
w3 | 4,000 .0190679 1.015951 -3.161212 3.477742
-------------+---------------------------------------------------------
w4 | 4,000 -.0083475 1.020264 -3.481928 3.343177
w5 | 4,000 .00874 1.003124 -4.002687 3.944189
w6 | 4,000 .0016545 .9941556 -3.615002 3.591007
w7 | 4,000 .0006976 1.01449 -3.297943 3.256187
w8 | 4,000 -.0037587 1.014113 -3.831774 3.498365
-------------+---------------------------------------------------------
w9 | 4,000 -.0095989 1.028091 -3.08722 3.859863
w10 | 4,000 .0187556 1.006128 -3.444188 3.649128
w11 | 4,000 -.002984 .9957664 -3.700773 3.406081
w12 | 4,000 .0078398 1.018744 -3.593562 4.082495
w13 | 4,000 -.0156626 1.010529 -3.729325 3.57018
-------------+---------------------------------------------------------
w14 | 4,000 .001853 1.006388 -3.269533 3.674261
w15 | 4,000 -.0226012 1.004162 -3.367424 3.241826
w16 | 4,000 -.0289284 .9867342 -3.406581 4.05419
.
end of do-file
Comment