Make frequency tables of text based variables
5 views (last 30 days)
Show older comments
My participants filled in a questionnaire which had 2 pooling variables ('Sex' and 'Age') and 80 other questions of which some answers were numbers (eg 'PhysicalActivityPerDaY' with 0, 1, 2, 3, 4 as possible answers) and some answers which were text-based (eg 'JobSecurity' with High, Not Sure, Low as possible answers).
I want to present the descriptive statistics of all variables per group, so the outcome of the code for variable 'JobSecurity' should have two tables which look roughly like this:
Sex JSHigh JSNot Sure JSLow
male 70% 15% 15%
female 80% 5% 15%
AgeGroup JSHigh JSNot Sure JSLow
18-35 20% 40% 40%
36-45 30% 30% 40%
46-55 50% 40% 10%
56-65 50% 30% 20%
I've tried experimenting with the varfun and grpstats functions, but they both seem unable to work with text-based variables. Is there a way around this?
Thanks in advance for your help
PS: Unfortunately the data collection has already been done by a previous group, so changing the way in which the data is stored (1,2,3 instead of high, not sure, low) is not an option.
0 Comments
Answers (1)
Cam Salzberger
on 13 Nov 2017
Hello Jesse,
This is precisely what the categorical data type is for. Once you have converted the text data in the table to categorical, you can essentially treat them as numeric when taking statistics and such.
Hope this helps!
-Cam
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!