我正在用 Ox(类似于 C、C++ 和 Java 的语法)模拟一些数据,但我被困在我的分配部分。假设,我有这个函数来模拟我的数据 g_mY:
decl g_mX, g_mY;
simuldata(const ct) // ct : number of observations
{
decl mx = ranbinomial(ct, 1, 1, 0.40)~ 100*ranu(ct, 1);
decl veps = rann(ct, 1);
decl vp = < .0485434;-.006764 ; -.0187657; -1.106632 ; .3647326 ; 1.11204 >;
g_mX = mx[][0:1] ; // regressors: Gender, Age.
decl cut1 = vp[2], cut2 = vp[3], cut3 = vp[4], cut4 = vp[5] ;
decl Yt = g_mX*vp[:1] + veps ; // latent variable
我想要做的是通过使用上面定义的切点(cut ...)和潜在变量(Yt)来创建 g_mY,并计算 g_mY 的替代值。更像这样:
g_mY = new matrix[rows(g_mX)][1] ; // dependent variable
for(decl i = 0; i < rows(g_mX); ++i)
{
if(Yt[i] < cut1)
{
g_mY[i] = < a number between 1 and 100, but != to a multiple of 5 >
}
else if(Yt[i]> cut1 .&& Yt[i]<= cut2)
{
g_mY[i] = 5 || g_mY[i] = 15 || g_mY[i] = 35 || g_mY[i] = 45 || g_mY[i] = 55 ||
g_mY[i] = 65 || g_mY[i] = 85 || g_mY[i] = 95 ;
// one of these multiples of 5 that are not multiples of 10
}
else if(Yt[i]> cut2 .&& Yt[i] <= cut3)
{
g_mY[i] = 10 || g_mY[i] = 20 || g_mY[i] = 30 || g_mY[i] = 40 ||
g_mY[i] = 60 || g_mY[i] = 70 || g_mY[i] = 80 || g_mY[i] = 90 ;
// one of these multiples of 10
}
else if(Yt[i] > cut3 .&& Yt[i] <= cut4)
{
g_mY[i] = 25 || g_mY[i] = 75 ; //either 25 or 75
}
else if(Yt[i] > cut4)
{
g_mY[i] = 50 || g_mY[i] = 100; //either 50 or 100
}
}
return 1
}
当我打印 g_mY 时,我只有零。我怎样才能成功地做到这一点?
非常感谢。