Stata Code: setref
version 7.0
program define setref, rclass
global rtextnames = "`1'"
local n = 1
local Rdtot = 0
char `1'[rscore] "`2'"
local Rdtot = `Rdtot' + `2'
macro shift
macro shift
while "`1'" ~= "" {
global rtextnames = "$rtextnames" + " `1'"
char `1'[rscore] "`2'"
local Rdtot = `Rdtot' + `2'
macro shift
macro shift
local n = `n' + 1
}
global RdN = `n' /* set up total ref text N */
global Rdmean = `Rdtot' / $RdN /* mean of ref scores */
tokenize $rtextnames /* now get SD of scores */
local Rdsqdev = 0
while "`1'" ~= "" {
local Rdsqdev = `Rdsqdev' + (``1'[rscore]' - $Rdmean)^2
macro shift
}
global RdSD = sqrt(`Rdsqdev' / ($RdN - 1))
end