program define qsturng * return a studentized range quantile, q_`3'(`1', `2') *! version 1.1.0 02Jul97 STB-46 dm64 version 5.0 capture assert (`1'>=2) & (`2'>=1) & (`3'*(1-`3') > 0) if _rc { di in red "invalid parameters in qsturng" error 499 } global S_1 1 local 2 = min(`2', 1E8) local 3 = string(`3') if `1' > 2 { global S_3 ".500 .750 .900 .950 .975 .990 .995 .999" if `3' > .99 & !(`3'==.995|`3'==.999) { global S_1 6 global S_2 .995 } else if `3' < .5 { global S_1 1 global S_2 .75 } else { qstux `3' } local pp $S_1 if $S_2 { tempname z local px 1 scalar `z' = -1/(1+1.5*invnorm((1+`3')/2)) qstuz 1 qstuz 2 qstuz 3 } local Nu = `2' >= 20 if `Nu' { global S_3 "20 24 30 40 60 120 1E8" qstux `2' if !$S_2 { local w 1 } else { local w : word $S_1 of $S_3 local w = ($S_2-`2')*`w'/(($S_2-`w')*`2') } local j $S_1 } else { local j = int(`2') local w = (`j'+1-`2')*`j'/`2' } local lr = log(`1' - 1) qstuy `lr' `j' `w' `pp' `Nu' if "`px'" != "" { tempname y1 y2 y3 rnu scalar `rnu' = `1'*cond(`2' < 1E8, 1/`2', 0) while `px' < 4 { scalar `y`px'' = log($S_1 + `rnu') local pp = 1 + `pp' if `px' < 3 { qstuy `lr' `j' `w' `pp' `Nu' } local px = `px' + 1 } scalar `y1' = (`y2'-`y1')/(scalar(S_2)-scalar(S_1)) scalar `y3' = (`y3'-`y2')/(scalar(S_3)-scalar(S_2)) if abs(2*(`y1'-`y3')/(`y1'+`y3')) < .01 { /* linear ipolation */ if `z' > scalar(S_2) { scalar `y1' = scalar(`y3') } scalar `y3' = 0 } else { /* quadratic ipolation */ scalar `y3' = (`y3'-`y1')/(scalar(S_3)-scalar(S_1)) scalar `y1' = `y1' - `y3'*(scalar(S_1)+scalar(S_2)) } scalar `y2' = `y2' - scalar(S_2)*(`y1'+`y3'*scalar(S_2)) global S_1 = exp( `y2'+`z'*(`y1'+`y3'*`z') ) - `rnu' } if `1' == 3 { global S_1 = $S_1 - .002/(1 + 12*(invnorm(`3'))^2) /* */ + cond(`2'>=4.364, 1/(191*`2'), 1/517 - 1/(312*`2')) } } global S_1 = $S_1 * sqrt(2) * invt(`2', `3') di %6.0g $S_1 end program define qstux local j : word count $S_3 local j = `j' + 1 local i 0 while `j' != `i' + 1 { local m = int((`i'+`j')/2) local k1 : word `m' of $S_3 if `k1' <= `1' { local i `m' } else { local j `m' } } local k1 : word `i' of $S_3 if `1' > `k1' { global S_2 : word `j' of $S_3 } else { global S_2 0 } global S_1 `i' end program define qstuy local B "StuRng`4'`5'" capture local t = rowsof(`B') if _rc { sturng`4' `5' } global S_1 = (((matrix(`B'[`2',4])*`1' + matrix(`B'[`2',3]))*`1' + /* */ matrix(`B'[`2',2]))*`1' + matrix(`B'[`2',1]))*`1' + 1 if `3' < 1 { local t = (((matrix(`B'[`2'+1,4])*`1' + matrix(`B'[`2'+1,3]))*`1' + /* */ matrix(`B'[`2'+1,2]))*`1' + matrix(`B'[`2'+1,1]))*`1' + 1 global S_1 = sqrt(`3'*$S_1*$S_1 + (1-`3')*`t'*`t') } end program define qstuz local w = $S_1 + `1' - 1 local w : word `w' of $S_3 scalar S_`1' = -1/(1 + 1.5*invnorm((1+`w')/2)) end program define sturng1 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng11 = ( .91056693, .0905643, -.0306423, .00247216 \ .9111864, .09025075, -.03063082, .00247742 \ .91177672, .08999655, -.03065594, .0024872 \ .91231114, .08984117, -.03073467, .00250316 \ .91275227, .08983757, -.0308878, .00252687 \ .91306072, .09003472, -.03113016, .0025581 \ .91324443, .09039963, -.03143097, .00258826) }; else { matrix StuRng10 = ( .87926501, .11943337, -.03830202, .00313082 \ .88533199, .10597296, -.03445005, .00277883 \ .89256507, .10092353, -.03310847, .00265952 \ .89707816, .09831089, -.03242582, .00259976 \ .90006202, .09665348, -.03199541, .00256276 \ .90217602, .09547228, -.03169158, .0025373 \ .90375638, .09457215, -.03146408, .00251886 \ .9049859, .09385741, -.03128785, .00250517 \ .90597129, .09327511, -.03114875, .00249489 \ .90677834, .09279253, -.03103765, .00248717 \ .90744954, .09238952, -.03094913, .00248151 \ .90801907, .09204584, -.03087698, .00247727 \ .90850574, .09175296, -.03081891, .00247427 \ .90892541, .09150257, -.03077263, .00247229 \ .90929061, .09128678, -.0307356, .00247107 \ .90961099, .09109948, -.03070602, .00247045 \ .90989339, .09093719, -.03068297, .00247035 \ .9101432, .0907969, -.03066571, .00247071 \ .91036808, .09067118, -.03065152, .00247124 \ .91056693, .0905643, -.0306423, .00247216) }; #delimit cr end program define sturng2 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng21 = ( .54657632, .02993201, -.01038611, .00076661 \ .54589528, .02825789, -.01023268, .00077042 \ .54517758, .02666597, -.01014073, .00078081 \ .54440051, .02518912, -.01012371, .00079859 \ .54353791, .02386304, -.01019446, .00082396 \ .54257321, .0227062, -.01035535, .00085497 \ .5415253, .02167795, -.01057782, .00088425) }; else { matrix StuRng20 = ( .70355052, .11851965, -.0341988, .00268685 \ .60681427, .09640203, -.02657619, .00199721 \ .57917988, .07926683, -.02150665, .00155629 \ .56719905, .06784222, -.01839978, .00129871 \ .56084919, .0597881, -.01634642, .00113623 \ .55704492, .05384168, -.01491295, .00102792 \ .55455816, .04930137, -.01387457, .00095321 \ .55282754, .04573712, -.0130997, .0009003 \ .55155921, .04288052, -.01250934, .00086226 \ .55059177, .04054931, -.01205136, .00083459 \ .54982811, .03861869, -.01169096, .00081432 \ .54920977, .03699778, -.01140353, .00079942 \ .54869622, .03562322, -.01117248, .00078854 \ .54826218, .03444531, -.01098499, .00078066 \ .54788798, .03342833, -.01083207, .00077509 \ .54756188, .03254255, -.01070635, .00077124 \ .54727316, .03176724, -.01060309, .0007688 \ .54701668, .03108182, -.01051699, .00076731 \ .54678518, .03047453, -.01044571, .00076666 \ .54657632, .02993201, -.01038611, .00076661) }; #delimit cr end program define sturng3 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng31 = ( .36647734, .01931003, -.00544452, .00034961 \ .36443353, .01738897, -.00527242, .0003536 \ .36235833, .01554957, -.00515926, .00036332 \ .36023647, .01381253, -.00511222, .00037881 \ .35806087, .01218656, -.00513245, .00039907 \ .35580894, .01069811, -.00522615, .00042323 \ .35357836, .00920392, -.00532841, .00044147) }; else { matrix StuRng30 = ( .65982991, .12536336, -.03587623, .00285515 \ .50453687, .09595738, -.02429232, .00173867 \ .44753805, .07748408, -.01861958, .00126062 \ .42045221, .06455939, -.01507354, .0009818 \ .40558559, .05468621, -.01247437, .00077451 \ .39611936, .04752865, -.01073286, .00064553 \ .38967085, .04204919, -.00947245, .00055641 \ .38499537, .03777705, -.00854549, .00049462 \ .38144767, .03437941, -.00785018, .0004513 \ .37866247, .03162486, -.00731763, .00042044 \ .37641409, .02935737, -.00690357, .00039834 \ .37455976, .02746331, -.00657656, .0003824 \ .37300059, .02586416, -.006316, .00037101 \ .37166864, .0245004, -.00610649, .00036295 \ .37051627, .02332607, -.00593649, .00035738 \ .36950928, .02230566, -.00579735, .00035362 \ .36862028, .02141289, -.00568289, .00035126 \ .36782804, .02062738, -.00558851, .00034999 \ .36711827, .01993069, -.00550997, .00034949 \ .36647734, .01931003, -.00544452, .00034961) }; #delimit cr end program define sturng4 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng41 = ( .29667538, .01743194, -.00415575, .00024242 \ .29386026, .01551539, -.00399307, .00024728 \ .29101786, .0136845, -.00388658, .00025721 \ .28814259, .01194681, -.00383736, .00027159 \ .28523177, .01030337, -.00384252, .00028911 \ .28229851, .00873171, -.00388857, .00030699 \ .27936494, .00719669, -.00395677, .00032194) }; else { matrix StuRng40 = ( .65493387, .12471695, -.03544692, .0028004 \ .47234976, .1018649, -.02588878, .0019161 \ .40437278, .07842101, -.01823804, .00122996 \ .36994883, .06395105, -.01403536, .00087877 \ .34985438, .05407703, -.01145244, .00067948 \ .33726203, .04645923, -.00956474, .00053869 \ .328574, .04068872, -.00822094, .00044314 \ .32218516, .0362805, -.00727161, .00038175 \ .31733134, .03276593, -.00655646, .00033825 \ .31351262, .02992028, -.00600962, .00030725 \ .31041962, .02759003, -.00558872, .00028547 \ .30785915, .02565621, -.00526085, .00027026 \ .30570206, .02403132, -.00500241, .00025973 \ .30385903, .022649, -.00479577, .00025246 \ .30226389, .02146265, -.00462943, .00024762 \ .30086857, .0204353, -.00449434, .00024455 \ .29963762, .01953822, -.00438384, .00024278 \ .29854143, .0187507, -.00429334, .00024203 \ .29756007, .01805274, -.00421805, .00024194 \ .29667538, .01743194, -.00415575, .00024242) }; #delimit cr end program define sturng5 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng51 = ( .25108713, .01658269, -.00344098, .00018435 \ .24764697, .0147049, -.00329128, .00019015 \ .24418758, .01291627, -.0031947, .00020039 \ .24070612, .01121941, -.00314921, .00021411 \ .23720886, .0096033, -.00314648, .00022953 \ .23371205, .00804196, -.0031715, .00024408 \ .2302372, .00650332, -.00320798, .00025548) }; else { matrix StuRng50 = ( .65364254, .12444618, -.03517677, .00275649 \ .46302411, .09770155, -.02421, .00173918 \ .38198891, .07758864, -.01768043, .00119039 \ .33913946, .06515357, -.01403988, .00089126 \ .31590083, .05389972, -.01092713, .00063775 \ .30085078, .04571554, -.00878338, .00046214 \ .2900264, .0401665, -.00756238, .00038699 \ .2823526, .03550015, -.00652389, .00031633 \ .27644026, .03188961, -.00578295, .00027081 \ .27174151, .02903518, -.00524495, .00024194 \ .26794022, .02669681, -.00483082, .00022174 \ .26480076, .02475151, -.00450591, .00020734 \ .2621575, .02311963, -.00425029, .0001974 \ .25989711, .02173856, -.00404835, .00019083 \ .25780225, .02071924, -.00393959, .00019182 \ .25622782, .01954081, -.00375871, .00018437 \ .25471738, .01865463, -.00365404, .00018325 \ .25337294, .01787886, -.00356908, .00018307 \ .25217032, .01719267, -.00349897, .00018349 \ .25108713, .01658269, -.00344098, .00018435) }; #delimit cr end program define sturng6 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng61 = ( .21066903, .01590246, -.00285674, .00013836 \ .20655531, .01408584, -.00272481, .00014544 \ .20243607, .01236247, -.00264172, .00015611 \ .19831355, .0107292, -.0026022, .00016913 \ .19419836, .00916957, -.00259478, .00018255 \ .19011211, .00765224, -.00260227, .00019395 \ .18607286, .00615257, -.00261193, .00020211) }; else { matrix StuRng60 = ( .65313286, .12503229, -.03554646, .00281221 \ .45387074, .09948076, -.02466564, .00178751 \ .36307028, .0801641, -.01812427, .00121947 \ .31801039, .06239261, -.01263132, .00073802 \ .28767475, .05455163, -.01078289, .00063134 \ .27102694, .04448576, -.00793943, .00038205 \ .25778407, .03915058, -.00677654, .00031069 \ .24830341, .03472848, -.00584769, .0002548 \ .24104449, .03128253, -.00519696, .00022362 \ .23546939, .02829487, -.00461514, .00019027 \ .2309415, .02587711, -.00417511, .00016716 \ .22715858, .02393478, -.00385728, .00015395 \ .22396336, .0223287, -.00361704, .00014616 \ .22123803, .02096811, -.00342691, .00014117 \ .21888521, .01980261, -.00327417, .00013803 \ .21683078, .01879752, -.00315126, .00013632 \ .21501963, .01792527, -.0030524, .00013575 \ .2134089, .01716444, -.00297314, .00013608 \ .21196708, .01649523, -.00290897, .00013701 \ .21066903, .01590246, -.00285674, .00013836) }; #delimit cr end program define sturng7 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng71 = ( .18898669, .01550028, -.00255145, .00011519 \ .18444814, .01372278, -.00243016, .00012295 \ .17991458, .01204495, -.00235632, .00013393 \ .17539345, .01045725, -.00232124, .00014654 \ .17089912, .00893961, -.00231152, .00015873 \ .16645311, .00746238, -.00231044, .00016841 \ .16207296, .00600429, -.00230683, .00017484) }; else { matrix StuRng70 = ( .65294063, .1250658, -.03554144, .00281108 \ .45192069, .09907939, -.02450668, .00177237 \ .3581599, .07788067, -.01722387, .00112507 \ .30600661, .06408402, -.01308244, .00079012 \ .27526817, .05297764, -.0099171, .00052869 \ .25442514, .04611539, -.00842455, .00045242 \ .24034709, .04004055, -.00699659, .00035513 \ .23074725, .03429684, -.00551562, .00022896 \ .22288336, .03052801, -.00471631, .00017594 \ .21645206, .02785802, -.00427905, .00016257 \ .21137689, .02550129, -.00387411, .00014509 \ .20723054, .02348577, -.00352968, .0001287 \ .20372017, .0218359, -.00327306, .00011878 \ .20070009, .0204795, -.00308607, .00011413 \ .19808365, .01933574, -.00294352, .00011225 \ .19580092, .01835144, -.00282992, .00011167 \ .19379319, .01749436, -.00273741, .00011181 \ .19201221, .01674367, -.00266198, .0001125 \ .19041982, .01608362, -.00260086, .00011366 \ .18898669, .01550028, -.00255145, .00011519) }; #delimit cr end program define sturng8 *! version 1.1.0 02Jul97 STB-46 dm64 #delimit ; if `1' { matrix StuRng81 = ( .15509187, .01469669, -.00206506, .00007981 \ .14975032, .01298877, -.00196402, .00008898 \ .14444745, .01138799, -.00190496, .00010024 \ .13919507, .00988415, -.00187778, .00011205 \ .13401717, .00844911, -.00186479, .00012211 \ .12893674, .00705744, -.00185069, .00012895 \ .12396658, .00570017, -.00182893, .00013282) }; else { matrix StuRng80 = ( .65388453, .12419594, -.03531096, .00279332 \ .45010099, .09869583, -.0242641, .00174033 \ .3505677, .07786883, -.01704182, .00110187 \ .29290411, .06387363, -.01281105, .0007633 \ .25642321, .0543328, -.010254, .00057882 \ .23495817, .04297656, -.00694565, .00028882 \ .21689178, .03841136, -.00599072, .00023992 \ .20463328, .03384613, -.00512302, .00020048 \ .19491063, .03042382, -.00448108, .00017129 \ .187555, .02732566, -.00389356, .0001435 \ .18186566, .02438295, -.0032293, .0000892 \ .17685942, .02241773, -.00290997, .00007563 \ .17254552, .02095226, -.00274246, .00007831 \ .16891721, .01965626, -.00258899, .00007869 \ .1658351, .01848787, -.00243966, .00007598 \ .16315611, .01747572, -.00231551, .00007379 \ .16078876, .01661661, -.00222224, .00007353 \ .15867819, .01588652, -.00215512, .00007501 \ .15678929, .01525376, -.0021047, .00007728 \ .15509187, .01469669, -.00206506, .00007981) }; #delimit cr end