我试图通过从3个其他变量(即A,B和C)创建变量D来计算z分数。我试图将D生成为:D =(AB)/ C但由于某种原因,当我这样做,它会产生非常大的数字。当我做了(A-B)时,它没有得到我用手计算时应该有的东西,而不是-2,我的-105.66。
变量A是'长'而变量B是'浮动',我不确定这是否是原因?我的stata语法是:
gen zscore= (height-avheight)/meansd
没用。
答案 0 :(得分:2)
你混淆了标量和变量。这是一个解决方案(切掉前四行并将x
替换为height
以使计算适合您的代码):
// example data
clear
set obs 50
gen x = runiform()
// summarize
qui su x
// store scalars
sca de mu = r(mean)
sca de sd = r(sd)
// z-score
gen zx = (x - mu) / sd
su zx
x
及其z-score zx
是带有许多值的变量,而mu
和sd
是常量。您可以使用标量或宏来编写Stata中的常量。
答案 1 :(得分:1)
我不确定你想要得到什么,但我将使用Stata的自动数据来解释。这是Stata的基本内容。说我想测试价格= 3
sysuse auto
sum price
#return list which is optional command
scalar myz=(3-r(mean))/r(sd) #r(mean) and r(sd) gives the mean and sd of price, if that is given you can simply enter the value for that
dis myz
-2.0892576
所以,这里的z值是-2.09。