--
I have some problems in the use of " byable ( recall ) ".
I am responsible for the statistical analysis of an survey of
satisfaction of the patients hospitalized in several Parisian
hospitals (26 hospitals with hundred of questionnaires realized by
hospital with drawn lots outgoing patients).
The questionnaire includes 43 items of satisfaction.
Every item containing 5 modalities of answer (from " very satisfied "
(5) to " In no way satisfied " (1)).
One of my objectives is to compare for every item the % of very
satisfied persons in a hospital to that of 25 other hospitals.
I realized a program allowing the comparison from a hospital to 25
others and I would like I could make this program run with the option
" by " hospital " ". I know that I have to use " byable ( recall )
but my attempts failed.
Somebody could put me on the way.
( At the moment the only solution which I found to by-pass this
problem is to use one " forvalues k = 1 ( 1 ) 26 {" myprog " `k '})
My program is the following one:
capture log close
log using boucles3, replace
set more off
# delimit ;
*program drop test_item;
program define test_item/*, rclass sortpreserve byable(recall)*/;
version 7.0 ;
use "SAPHORA_2003:SAPHORA_2003nwb", clear ;
preserve ;
tempfile wks ;
save "`wks'" ;
use "`wks'", clear ;
local i = v3b ;
keep v1 v3 v3b v18 v19 v23 v24 v20 v25 v21 w22 w37 v35 w27 w32 v38
/*w39*/ v29 w30 w26 new_coef`i' ;
local h : label hôplbl `i' ;
di as text _col(10) "Hôpital " "`h'" _col(45)
"Ensemble des hôpitaux sauf " "`h'" ;
di as text _dup(110) "-" ;
di as text "item" _col(10) "+" _col(20) "-" _col(30) "total "
_col(45) "+" _col(55) "-" _col(65) "total "
_col(80) %5.2f " chi2 " _col(90) %5.2f " p " ;
di as text _dup(110) "-" ;
foreach var of varlist v18 v19 v23 v24 v20 v25 v21 w22 w37 v35 w27
w32 v38 /*w39*/ v29 w30 w26 { /*BOUCLE POUR CHAQUE ITEM*/
tempvar item;
quietly gen `item' = new_coef`i' if `var' == 5;
quietly recode `item' . = 0 if `var' ~= 5 & `var' ~= . ;
local j = 26 ;
local npc = 0 ;
local wpc = 0 ;
quietly summarize `item' if v3b == `i' ;
if r(N) == 0 {
local n`i' = r(N) ;
local m`i' = r(N)
};
else if r(N) ~= 0 {
local n`i' = r(N) * r(mean) ;
local m`i' = r(N) * (1 - r(mean))
};
while `j' > 0 {
/*BOUCLE
INTERNE POUR CALCUL PONDÉRÉ DU % DE */
if `j' ~= `i' {
/*TRÈS
SATISFAITS POUR LES AUTRES HÔPITAUX */
quietly summarize `item' if v3b == `j';
local n`j' = r(N) ;
if r(N) == 0 {
local p`j' = 0
};
else if r(N) ~= 0 {
local p`j' = r(mean)
};
local npc = `npc' + `n`j'' ;
local wpc = `p`j'' + `wpc' ;
};
else {
local j = `j'
};
local j = `j'- 1
};
local b = `npc' * `wpc' ;
local d = `npc' * (1 - `wpc') ;
local A = round(`n`i'',1);
local C = round(`m`i'',1);
local B = round(`b',1);
local D = round(`d',1);
/*TEST DE COMPARAISON DE L'HÔP. i */
if `A' ~= 0 & `C' ~= 0 & `B' ~= 0 & `D' ~= 0 {
quietly tabi `A' `B' \ `C' `D' , all exact col ;
di "`var'" _col(10) %5.1f 100 * `A'/(`A'+`C')
_col(20) %5.1f 100 *
`C'/(`A'+`C')
_col(30) `A'+`C'
_col(45) %5.1f 100 *
`B'/(`B'+`D')
_col(55) %5.1f 100 *
`D'/(`B'+`D')
_col(65) `B'+`D'
_col(80) %5.2f r(chi2) _col(90) %5.2f r(p) as result ;
di as text _dup(110) "-"
};
else if (`A' == 0 | `C' == 0 | `B' == 0 | `D' == 0)
& ( `A'+`C' ~= 0 ) {
di "`var'" _col(10) %5.1f 100 * `A'/(`A'+`C')
_col(20) %5.1f 100 *
`C'/(`A'+`C')
_col(30) `A'+`C'
_col(45) %5.1f 100 *
`B'/(`B'+`D')
_col(55) %5.1f 100 *
`D'/(`B'+`D')
_col(65) `B'+`D'
_col(80) " non évaluable ";
di as text _dup(110) "-" ;
else if ( `A'+`C' == 0 ) {
di "`var'" _col(10) %5.1f " "
_col(20) %5.1f " "
_col(30) " 0 "
_col(45) %5.1f 100 *
`B'/(`B'+`D')
_col(55) %5.1f 100 *
`D'/(`B'+`D')
_col(65) `B'+`D'
_col(80) " non évaluable ";
di as text _dup(110) "-" ;
}
};
end;