/*
     sbrowni: Spearman-Brown reliability correction for test length
     Version 1.0 -- Date: August 02 1998
     By: Hervé CACI (hcaci@pratique.fr)

     sbrowni .87 23 .76 (initial reliability - #items - desired reliability)
     sbrowni .87 23 18  (initial reliability - #items - #items)
*/

program define sbrowni
version 5.0

parse "`*'", parse(" ,")

confirm number `1'
local rel0 `1'
if `rel0' <=0 | `rel0' >1  {
     display in red "The initial reliability coefficient must be within the
[0; 1] interval"
     exit
}

confirm integer number `2'
local count0 `2'
if `count0'<=1  {
     display in red "The initial number of items must be a positive integer"
     exit
}

confirm number `3'
local rel1 `3'
if `rel1' <=0  {
     display in red "The third parameter is meaningless"
     exit
}
display _n in green "Spearman-Brown reliability correction for test length"
display in green _dup(53) "-" _n
display in green "Initial reliability     = "%4.3f `rel0'
display in green "Initial number of items = "%3.0f `count0'

if `rel1' <=1 {
     local count1 = (`rel1'*(1-`rel0'))/(`rel0'*(1-`rel1'))
     display in green "Desired reliability     = " %4.3f `rel1' _n
     display in green "Estimated test length   = " %4.0f `count1'*`count0'
}
else {
     local count1=`rel1'/`count0'
     local rel2=(`count1'*`rel0')/(1+(`count1'-1)*`rel0')
     display in green "Increased test length   = " %3.0f `rel1' _n
     display in green "Estimated reliability   = " %4.3f `rel2'
}
end