我们使用stata中的矩阵函数以及循环变量赋值生成圣诞树的
主干
的数据,并生成
散点图
。
clear
matrix
L = (0.03, 0.85, 0.8, 0.20, -0.20, 0.25, -0.20\ 0.00 ,0.00, 0.0, -0.08,
0.08, -0.10, 0.10\ 0.00, 0.00, 0.0 , 0.15, 0.15, 0.12, 0.12\ 0.10,
0.85, 0.80, 0.22, 0.22, 0.25, 0.20)
mat list L
matrix B = ( 0, 0.0, 0.0,0.00, 0.00, 0.0, 0.0\ 0, 1.5, 1.5, 0.85, 0.85, 0.3, 0.4)
mat list B
matrix prob = (0.02, 0.6,.08, 0.07, 0.07, 0.07, 0.07)
set obs 100000
gen x1 = .
gen x2 = .
gen k = int(runiform(1,7))
replace x1 = 0 if _n==1
replace x2 = 2 if _n==1
forvalues i = 2(1)100000 {
mat x = (x1[`i'-1],x2[`i'-1])
mat a = (L[1,k[`i']],L[3,k[`i']]\L[2,k[`i']],L[4,k[`i']])
mat b = a'*x'+ B[1...,k[`i']]
replace x1 = b[1,1] if _n == `i'
replace x2 = b[2,1] if _n == `i'
di `i'
}
scatter x2 x1 ,color(green) jitter(2) title("Merry Christmas")