Announcement

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

  • graph for occurrences of multiple variables

    I´m struggling to graph occurrences of multiple variables in one graph. My data describes on which spinal level (spond_niv__x) patients (record_id) had surgery, it can be surgery on multiple levels (see below).
    What I want is a graph that show the number/frequency of levels done surgery on. 5 bars in one graph, each bar representing the level (spond_niv__x) and showing the number of occurrences.
    I tried to use "graph bar" and "catplot" but it shows 2 bars for each level (checked and unchecked), I only want the checked to appear. Perhaps I need to convert my data?

    data is :

    --------------------------------------------------------------------------------
    record_id Record ID
    --------------------------------------------------------------------------------

    Type: Numeric (int)

    Range: [1,131] Units: 1
    Unique values: 131 Missing .: 0/131

    --------------------------------------------------------------------------------
    spond_niv___1 Spondylodese niveauer (choice=L1-L2)
    --------------------------------------------------------------------------------

    Type: Numeric (byte)
    Label: spond_niv___1_

    Range: [0,1] Units: 1
    Unique values: 2 Missing .: 0/131

    Tabulation: Freq. Numeric Label
    129 0 Unchecked
    2 1 Checked

    --------------------------------------------------------------------------------
    spond_niv___2 Spondylodese niveauer (choice=L2-L3)
    --------------------------------------------------------------------------------

    Type: Numeric (byte)
    Label: spond_niv___2_

    Range: [0,1] Units: 1
    Unique values: 2 Missing .: 0/131

    Tabulation: Freq. Numeric Label
    124 0 Unchecked
    7 1 Checked

    --------------------------------------------------------------------------------
    spond_niv___3 Spondylodese niveauer (choice=L3-L4)
    --------------------------------------------------------------------------------

    Type: Numeric (byte)
    Label: spond_niv___3_

    Range: [0,1] Units: 1
    Unique values: 2 Missing .: 0/131

    Tabulation: Freq. Numeric Label
    101 0 Unchecked
    30 1 Checked

    --------------------------------------------------------------------------------
    spond_niv___4 Spondylodese niveauer (choice=L4-L5)
    --------------------------------------------------------------------------------

    Type: Numeric (byte)
    Label: spond_niv___4_

    Range: [0,1] Units: 1
    Unique values: 2 Missing .: 0/131

    Tabulation: Freq. Numeric Label
    82 0 Unchecked
    49 1 Checked

    --------------------------------------------------------------------------------
    spond_niv___5 Spondylodese niveauer (choice=L5-S1)
    --------------------------------------------------------------------------------

    Type: Numeric (byte)
    Label: spond_niv___5_

    Range: [0,1] Units: 1
    Unique values: 2 Missing .: 0/131

    Tabulation: Freq. Numeric Label
    97 0 Unchecked
    34 1 Checked


  • #2
    I think this should get you closer to what you want.

    Code:
    clear 
    set seed 314159
    set scheme s1color 
    set obs 131 
    
    gen Record_Id = _n 
    label def whatever 0 Unchecked 1 Checked 
    
    forval j = 1/5 {
        gen spond_niv___`j' = runiform() > `j' * 0.1 
        label val spond_niv___`j' whatever 
    }
    
    * you start here 
    preserve 
    
    reshape long spond_niv___, i(Record_Id) j(level) 
    
    catplot level if spond_niv___ == 1 , ytitle(Counts by spinal level)
    
    restore

    Comment


    • #3
      Reshaping into long data did the trick!
      Thank you very much, I really value the help

      Comment

      Working...
      X