program define raschres,rclass
syntax varlist [, resname(string)]

tempname diff theta
matrix `diff'=r(beta)
matrix `theta'=r(theta)

if "`resname'"=="" {
   local resname=res
}

tokenize `varlist'
local nbitems: word count `varlist'
tempname score  lt
genscore `varlist',score(`score')
gen `lt'=.

forvalues i=0/`nbitems' {
   replace `lt'=`theta'[1,`i'] if `score'==`i'
}

forvalues i=1/`nbitems'{
   tempname p`i' res`i'
   gen `p`i''=exp(`lt'-`diff'[1,`i'])/(1+exp(`lt'-`diff'[1,`i'])
   gen `resname'`i'=(1-`p`i'')/sqrt(`p`i''*(1-`p`i''))
}
pca `resname'*








end