Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: multiple response to binary


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: multiple response to binary
Date   Fri, 12 Jul 2002 13:01:53 -0400

Not sure this counts as "elegant", but if all your multiple case
variables follow the pattern f*m*, then the following program should do
it for you.  Be sure to modify the list of stubs to be complete:

*****************begin multcase.ado
prog define multcase
	version 7
	foreach stub in f4 f6 f8 {	/* <==== ADD LIST OF STUBS */
		vl `stub'*
		local varlist `r(varlist)'
		local nstub : word count `varlist'
		forval i=1/`nstub' {
			gen `stub'_val_`i' = .
			forval v=1/`nstub' {
				qui replace `stub'_val_`i' = 0 if
`stub'm`v'!=. & `stub'_val_`i'==.
				qui replace `stub'_val_`i' = 1 if
`stub'm`v'==`i'
			}
		}
	}
end

prog define vl, rclass
	syntax varlist
	return local varlist `varlist'
end
***************end multcase.ado

> -----Original Message-----
> From: Lee Sieswerda [mailto:Lee.Sieswerda@tbdhu.com] 
> Sent: Friday, July 12, 2002 12:35 PM
> To: Statalist (E-mail)
> Subject: st: multiple response to binary
> 
> 
> Hello all:
> I have a data management problem (WinNT4, Stata v7).
> 
> I have data from a questionnaire where some of the questions allow the
> respondent to choose multiple responses. Lets say there 7 
> possible responses
> and they could choose any number of them. I would code this 
> as a set of 7
> binary variables. Unfortunately, the way it was coded was not so
> straightforward. It was coded across 7 variables, but the 
> responses were
> simply entered in the order in which they were given by the 
> respondent. So
> the data look like this:
> 
> f4m1      f4m2      f4m3      f4m4      f4m5      f4m6      f4m7
>     1         7         4         .         .         .         .
>     1         .         .         .         .         .         .
>     1         .         .         .         .         .         .
>     1         .         .         .         .         .         .
>     7         3         .         .         .         .         .
>     1         .         .         .         .         .         .
>     1         2         3         4         .         .         .
>     1         2         3         4         6         .         .
>     1         2         7         .         .         .         .
>     1         .         .         .         .         .         .
> 
> As you can see, you cannot simply tabulate the number of people who
> responded 1, 2 , 3 etc because the responses are scattered over the 7
> variables in a different order for every person. The folks 
> who provided me
> with this data use SPSS and they get around this problem by 
> using "multiple
> responses sets". In SPSS, you can define a set of variables 
> as a multiple
> response set (in this case, seven variables) and then ask for 
> tables of
> frequencies and crosstabs generated from across the 7 
> variables. It works,
> but I'd much rather use Stata than SPSS. Also, the SPSS 
> solution is limited
> to simple tables and doesn't permit you to get chi-square or other
> statistics.
> 
> Now, in Stata I know I can generate dummy variables from this 
> mess like
> this:
> gen dum1 = 0
> replace dum1 = 1 if f4m1==1 | f4m2==1 | f4m3==1 etc.
> replace dum1 = . if f4m1==. & f4m2==. & f4m3==. etc.
> gen dum2 = 0
> etc.
> 
> However, this is tedious in the extreme and there are many of 
> these multiple
> response questions in the dataset. I could automate the 
> procedure somewhat
> using -foreach-, but its still more brute force than 
> elegance. Someone told
> me about a SAS solution to this problem using an array procedure. Does
> anyone have a nice elegant Stata solution to this problem?
> 
> Thanks,
> 
> Lee
> 
> Lee Sieswerda, Epidemiologist
> Thunder Bay District Health Unit
> 999 Balmoral Street
> Thunder Bay, Ontario
> Canada  P7B 6E7
> Tel: +1 (807) 625-5957
> Fax: +1 (807) 623-2369
> Lee.Sieswerda@tbdhu.com
> www.tbdhu.com
> 
> *
> *   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/
> 
*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index