Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying a Complex Table

    Good morning everyone!

    I'm quite new to STATA and try to display a complex table, but even after hours of Googlin' I wasn't able to do so...


    I have a dataset from a survey looking like this: The dataset contains the branche of the participants (there are 9 possible Branches) and 26 Questions. For each of these 26 Questions, one answer (Q_Option1 OR Q_Option2 OR Q_Option3) is chosen (Single Choice). For all variables, Branche and Question1-Question26, only a single variable is saved (no multiple selection was possible).
    The answer options (Q_Option1 to Q_Option3) for questions Question1 to Question26 are always the same.


    Branche Question1 Question2 Question3 Question4 Question5 Question6 Question8 ... Question26
    Br_Option1
    Br_Option2
    ...
    Br_Option9
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3
    Q_Option1
    Q_Option2
    Q_Option3



    I would now like to have STATA create a table which looks like this: Having the total Number of selected answer options (N) per Question and then broken down by Branche. I hope I was able to make clear what I mean, I'd like the table to look like the following:


    by Question
    and Branche
    Q_Option1 Q_Option2 Q_Option3
    Question1

    Br_Option1
    Br_Option2
    ...
    Br_Option9
    N

    N
    N
    ...
    N
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    Question2

    Br_Option1
    Br_Option2
    ...
    Br_Option9
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    Question3

    Br_Option1
    Br_Option2
    ...
    Br_Option9
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    ...
    ...
    ...
    ...
    Question26

    Br_Option1
    Br_Option2
    ...
    Br_Option9
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N
    N

    N
    N
    ...
    ​​​​​​​N



    I am very grateful for any hints and tips, as I am really despairing on this...
    Thanks a lot for your help!!
    Stephan

  • #2
    Hi, Stephan, something like this perhaps?

    Click image for larger version

Name:	branche.png
Views:	1
Size:	25.5 KB
ID:	1614722



    (sorry for the nonsense data).

    Comment


    • #3
      In case that's what you wanted the code is as follows:
      Code:
      clear all
      sysuse nlsw88
      rename industry branche
      label variable branche "Branche"
      set seed 12345
      generate byte q1=runiform()*5+1
      label variable q1 "How did you like the food?"
      generate byte q2=runiform()*5+1
      label variable q2 "How did you like the service?"
      generate byte q3=runiform()*5+1
      label variable q3 "How did you like the facilities?"
      label define cats 1 "Very Poor" 2 "Poor" 3 "Fair" 4 "Good" 5 "Excellent"
      label values q1 q2 q3 cats
      
      program define tabme
        table branche q1
        table branche q2
        table branche q3
      end
      tabme

      The whole grey text is just data preparation for the example.
      And in case anyone wonders why a program is needed here - that's to avoid intermittent lines when Stata echoes commands from the do-file to the output window.


      Hope this helps.
      Best, Sergiy Radyakin

      Comment

      Working...
      X