Hugh wrote:
I posted my question yesterday, but realized there were some errors as
Nick rightly pointed out. Here is another attempt at what I am trying
to do.
Assume my data is as follows:-
id q23 q24 q25 q29 q30 q31
1 3 1 1 4
2 4 2 3 5 3 2
3 2 2
4 3 3
5 1 3 2 4 6 1
q23-q25 and q29-q31 are categorical variables.
q23-q25 each has 4 categories 1, 2, 3 & 4. I want to ignore category 4.
q29-q31 each has 6 categories 1, 2, 3, 4, 5 & 6. I want to ignore category 6.
I am interested in a cross tabulation.
Here's what I need:-
count if q23==1 & (q29==1 | q29==2);
count if q24==1 & (q30==1 | q30==2);
count if q25==1 & (q31==1 | q31==2);
/* I then need to sum these */; Lets call the total "a"
count if q23==1 & q29==3;
count if q24==1 & q30==3;
count if q25==1 & q31==3;
/* I then need to sum these */; Lets call the total "b"
count if q23==1 & q29==4;
count if q24==1 & q30==4;
count if q25==1 & q31==4;
/* I then need to sum these */; Lets call the total "c"
count if q23==1 & q29==5;
count if q24==1 & q30==5;
count if q25==1 & q31==5;
/* I then need to sum these */; Lets call the total "d"
THEN GO THROUGH THE SAME PROCEDURE using q23=2, q24=2 & q25=2. Assume
the four values generated are e, f, g and h
FINALLY DO THE SAME using q23=3, q24=3 & q25=3. Assume the four values
generated are i, j, k and l
I finally need the results in a table such as
NP FP G
< 24% a e i
25-49% b f j
50-74% c g k
75% d h l
---------------------------------------------
Perhaps I understand Hugh right, perhaps not. Here is a
not too elegant, but hopefully transparent solution:
clear
input id q23 q24 q25 q29 q30 q31
1 3 1 . 1 4 .
2 4 2 3 5 3 2
3 2 . . 2 . .
4 3 . . 3 . .
5 1 3 2 4 6 1
end
gen a = q23==1 & (q29==1 | q29==2)
replace a=a+1 if q24==1 & (q30==1 | q30==2)
replace a=a+1 if q25==1 & (q31==1 | q31==2)
gen b = q23==1 & q29==3
replace b=b+1 if q24==1 & q30==3
replace b=b+1 if q25==1 & q31==3
gen c = q23==1 & q29==4
replace c=c+1 if q24==1 & q30==4
replace c=c+1 if q25==1 & q31==4
gen d = q23==1 & q29==5
replace d=d+1 if q24==1 & q30==5
replace d=d+1 if q25==1 & q31==5
egen ta=total(a)
egen tb=total(b)
egen tc=total(c)
egen td=total(d)
list
Hope this helps
Svend
________________________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [email protected]
_________________________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/