Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: tabout for multiple likert-scale questions


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: tabout for multiple likert-scale questions
Date   Mon, 27 Sep 2010 14:06:57 +0000

<>

This is a frustration I've encountered in the past, and usually the solution has been to just write the headers for each table and then manually move the cells around in excel.
For example, using my code in the previous email you would:  Change the "h1(nil) h2(nil) h3(nil)" part in the loop to "h1(nil) h3(nil)" so that you can see the categories for each table/panel.  You'll see that for Q2, category 4 is missing and so category 5 for Q2 lines up with category 4 for Q1.  You can move the Q2 category 5 cells to the right in excel and then delete the row containing the table h2 for Q2 to make them line up.  This is pain if you've got lots of questions.


I'm glad you asked about this because it made me think about using tabout in a different way to get categories with zero frequencies -- that is to write a loop to create each category/response as a separate column (including the omitted responses as zeros) and use then "summary" table option in -tabout- to write the tables. (Though you may notice that by the time you've constructed all the elements in the loop below, the benefits of -tabout- diminish-- you are probably a few steps away from being able to -collapse- the table and write it manually).



**************************!
**using your example data:
clear
inp Q1 Q2 Q3
1 2 1
2 5 1
4 1 1
1 1 1
5 1 .
3 3 5
end



**Again, to write the headers one time, you'll need to do Q1 separately:

//question 1//
preserve
keep Q1
egen totQ1 = count(Q1) if !mi(Q1)

gen question="Q1"
	forval l = 1/5 {

**create values for each category of Q1:
g Q1_freq`l' = 1 if Q1==`l'
egen countQ1_`l' = count(Q1) if Q1==`l'
g Q1_pct`l' = (countQ1_`l'/totQ1)*100
replace Q1_freq`l' = 0 if mi(Q1_freq`l')
replace Q1_pct`l' = 0 if mi(Q1_pct`l')


**this builds the c() options in -tabout-, sum **
local options   `options'  max Q1_freq`l' max Q1_pct`l'
}

tabout question using table1.xls, replace sum c(`options' max totQ1)  ///
ptotal(none) h1(| Likert Questions ) h3(nil)  ///
h2(| Strongly_Disagree | | Disagree | | Neutral || Agree | |Strongly_Agree || TOTAL) ///
format(0c 0p 0c 0p 0c 0p 0c 0p 0c 0p 0c)
**edit h2 with your question labels (be sure to avoid spaces, use underscores)**

restore



//remaining questions//


**! change the values below for the number of Q's:
forval n = 2/3 {
	preserve
keep Q`n'
egen totQ`n' = count(Q`n') if !mi(Q`n')

local options
gen question="Q`n'"

	forval l = 1/5 {

g Q`n'_freq`l' = 1 if Q`n'==`l'
egen countQ`n'_`l' = count(Q`n') if Q`n'==`l'
g Q`n'_pct`l' = (countQ`n'_`l'/totQ`n')*100
replace Q`n'_freq`l' = 0 if mi(Q`n'_freq`l')
replace Q`n'_pct`l' = 0 if mi(Q`n'_pct`l')

**this builds the c() options in -tabout-, sum **
local options   `options'  max Q`n'_freq`l' max Q`n'_pct`l'
}

tabout question using table1.xls, append sum c(`options' max totQ`n')  ///
format(0c 0p 0c 0p 0c 0p 0c 0p 0c 0p 0c) ///
ptotal(none) h1(nil) h2(nil) h3(nil)
restore
}

**************************!
As always, watch for wrapping issues with the code above.


- Eric

____
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754






On Sep 27, 2010, at 6:09 AM, Vicki Livingstone wrote:

> Hi Eric,
> 
> Many thanks for that - It works perfectly once none of the questions have a 
> category where the frequency is zero.
>  
> Suppose that there were only two questions and the data was as follows:
> Q1 Q2
> 1 2
> 2 5
> 4 1
> 1 1
> 5 1
> 3 3
>  
>  When you run the syntax, you get the following output:    
>  
> question        1       1       2       2       3       3       4       4       
> 5       5       Total   Total
>  Frequency       Percent Frequency       Percent Frequency       Percent 
> Frequency       Percent Frequency    Percent Frequency       Percent
> Q1      2       33%     1       17%     1       17%     1       17%     1       
> 17%     6       100%
> Q2      3       50%     1       17%     1       17%     1       17%     6       
> 100%
>  
> Is there a way to include categories with zero observed frequency using tabout?
> 
> Thanks again, 
> Vicki 
> 
> 
> 
> ----- Original Message ----
> From: Eric Booth <[email protected]>
> To: "<[email protected]>" <[email protected]>
> Sent: Sat, 25 September, 2010 18:21:29
> Subject: Re: st: tabout for multiple likert-scale questions
> 
> <>
> 
> 
> **************************!
> clear
> set obs 200
> forval n = 1/5 {
>     g Q`n' = 1+int((7-1+1)*runiform())
>     }
> 
> gen question="Q1"
> 
> **Q1**
> tabout question Q1 using table1.xls, replace cell(freq row) format(0c 0p) ///
> clab(Frequency Percent) ptotal(none) h1(| Likert Scale Questions)
> drop question
> 
> **Q2 - Q5**
> forval n = 2/5 {
> preserve
>     keep Q`n'
> gen question="Q`n'"
> tabout question Q`n' using table1.xls, append cell(freq row) format(0c 0p) ///
> ptotal(none) h1(nil) h2(nil) h3(nil)
> restore
> }
> **************************!
> 
> - Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
> 
> 
> On Sep 25, 2010, at 3:19 AM, Vicki Livingstone wrote:
> 
>> Hi all,
>> 
>> I am running descriptives for a questionnaire that has many questions measured 
> 
> 
> 
> 
>> on the same Likert scale. What I would like to output is a table where 
>> the rows correspond to each question and the columns are the n(%) for 
>> each category of response within the question.
>> 
>> Using the following commands, I can output the results for an individual 
>> question. 
>> gen new=1
>> tabout new Q1 using table1.xls, replace cell(freq row) format(0 0) 
>> clab(Frequency Percent)
>> 
>> Is there a way of including all Likert questions in the output?
>> 
>> Many thanks in advance, 
>> Vicki Livingstone
>> 


__
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index