I'm trying to create a table of multiple variables with identical response categories but can't get it the way I want using collect commands so I am resorting to manipulating the data instead. I would like to figure out how to do it with collect commands. Any suggestions? Thanks.
Code:
clear all input x1 x2 x3 1 1 1 2 2 2 3 1 3 1 1 2 2 2 1 end label define rating 1 "Meh" 2 "Good" 3 "Super" label value x1-x3 rating label var x1 "Pineapple on Pizza" label var x2 "Manchester United" label var x3 "SPSS" /*** I can get this table . table (var), statistic(fvpercent x1 x2 x3) statistic(fvfrequency x1 x2 x3) ------------------------------------------------------------------------------ | Factor-variable percent Factor-variable frequency -------------------------+----------------------------------------------------- Pineapple on Pizza=Meh | 40.00 2 Pineapple on Pizza=Good | 40.00 2 Pineapple on Pizza=Super | 20.00 1 Manchester United=Meh | 60.00 3 Manchester United=Good | 40.00 2 SPSS=Meh | 40.00 2 SPSS=Good | 40.00 2 SPSS=Super | 20.00 1 ------------------------------------------------------------------------------- But I want to produce this table: --------------------------------------------------------- | Response | Meh Good Super | % N % N % N ---------------------+----------------------------------- Item Rated | Pineapple on Pizza | 40.00 2 40.00 2 20.00 1 Manchester United | 60.00 3 40.00 2 SPSS | 40.00 2 40.00 2 20.00 1 --------------------------------------------------------- *****/ *** Here is my workaround: *** loop over variables and create a table for each one *** would like to avoid creating a temporary variable but *** that is my solution to combining them into a single dimension *** I would like to find a way to do it after the collect combine instead collect clear foreach var of varlist x1-x3 { capture drop _var gen _var = `var' local val : value label `var' label value _var "`val'" table () (var) , statistic(fvpercent _var) statistic(fvfrequency _var) collect rename Table `var' } ** Combine the tables collect combine New = x1 x2 x3 *** copy the variable labels to the collection labels foreach var of varlist x1 x2 x3 { local vlab: var label `var' collect label levels collection `var' "`vlab'" } collect label levels result fvfrequency "N" fvpercent "%", modify collect label dim _var "Response" collect label dim collection "Item Rated" collect layout (collection) (_var#result)
Comment