Announcement

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

  • tables with results across columns

    In general, dtable works wonders. I am running into an issue with listing all results in one column. Right now I have a series of attendence variables, with 4 possible responses (coded 0 to 3; absent, attended; excused; partial). Rather than listing vertically across all events, I want to list so the four possible responses are all columns.

    Here's what I'm getting now:
    orientation
    Absent 2 (3.5%)
    Attended 54 (94.7%)
    Partial 1 (1.8%)
    module1
    Attended 141 (94.6%)
    Excused 7 (4.7%)
    Partial 1 (0.7%)
    using the code
    Code:
     dtable i.(orientation module1),  title("Program Participation")
    Would there be a way to format a table which had Absent, Attended, Partial, and Excused as columns, and orientation and module as rows (and numbers corresponding appropriately)?


  • #2
    One way is to change the structure of your data before creating the table.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(orientation module1)
    1 2
    1 1
    3 1
    1 3
    3 2
    3 2
    3 2
    1 1
    1 2
    2 3
    0 1
    0 1
    0 1
    3 3
    1 3
    3 3
    1 3
    3 1
    0 2
    1 1
    end
    label values orientation lab1
    label def lab1 0 "Absent", modify
    label def lab1 1 "Attended", modify
    label def lab1 3 "Partial", modify
    label values module1 lab2
    label def lab2 1 "Attended", modify
    label def lab2 2 "Excused", modify
    label def lab2 3 "Partial", modify
    
    frame put *, into(table)
    frame table{
        decode orientation, gen(responsesOrientation)
        decode module1, gen(responsesModule)
        keep responses*
        gen long obsno=_n
        reshape long responses, i(obsno) string
        lab define Responses 0 "Absent" 1 "Attended" 2 "Excused" 3 "Partial"
        lab define Course 1 "Orientation" 2 "Module"
        encode _j, gen(Course) label(Course)
        encode responses, gen(Responses) label(Responses)
        dtable i.Course, by(Responses)
    }
    frame drop table
    Res.:

    Code:
    .     dtable i.Course, by(Responses)
    
    ---------------------------------------------------------------------
                                         Responses                       
                    Absent    Attended    Excused    Partial     Total   
    ---------------------------------------------------------------------
    N              4 (10.3%) 16 (41.0%)  6 (15.4%) 13 (33.3%) 39 (100.0%)
    Course                                                               
      Orientation 4 (100.0%)  8 (50.0%)   0 (0.0%)  7 (53.8%)  19 (48.7%)
      Module        0 (0.0%)  8 (50.0%) 6 (100.0%)  6 (46.2%)  20 (51.3%)
    ---------------------------------------------------------------------
    Last edited by Andrew Musau; 07 Jun 2024, 18:12.

    Comment

    Working...
    X