Announcement

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

  • Extent of missingness

    Hi Statalist! I would like to create a table with the number and percentage of missing VALUES in groups of variables (or the entire dataset, as the 3 outcomes can be separated) by treatment arm, for 3 outcome measures (each outcome measure consists of about 30 variables). I can't seem to get the n and % of all variables. All of my data is numeric.

    In the end, it should look something like this:
    Arm 1 Arm 2 Total
    Outcome 1 n (%) n (%) n (%)
    Outcome 2 n (%) n (%) n (%)


    Thanks for your help!

  • #2
    It would have been helpful had you posted some example data. Since you didn't I cannot test this code, but the gist of it is correct.

    Code:
    capture postutil clear
    tempfile missing_table
    postfile handle str32 outcome byte arm long mcount using `missing_table'
    
    count if arm == 1
    local arm1_denom = r(N)
    count if arm == 2
    local arm2_denom = r(N)
    
    foreach v of varlist list_of_outcome_variables_here {
        forvalues a = 1/2 {
            count if missing(`v') & arm == `a'
            post handle ("`v'") (`a') (`r(N)')
        }
    }
    postclose handle
    
    use `missing_table', clear
    gen mpct = .
    forvalues a = 1/2 {
        replace mpct = 100*mcount/`arm`a'_denom' if arm == `a'
    }
    reshape wide mcount mpct, i(outcome) j(arm)
    gen mcount_total = mcount1 + mcount2
    gen mpct_total = 100*mcount_total/(`arm1_denom' + `arm2_denom')
    format mpct* %3.2f
    format mcount* %1.0f
    list, noobs clean
    Note: This code overwrites the data originally in memory with the table. If you need to recover the original data after outputting the table, then just insert a -preserve- command before -use `missing_table', clear-, and then a -restore- command at the end.

    Comment

    Working...
    X