Announcement

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

  • Descriptive statistics generated with "misum": Creating an excel table for imputed data

    Hi list,

    I am looking to generate a table that will allow easy comparison of changes in means and standard deviations across observed and imputed data for a list of variables.

    Creating the first (left-hand) side of the table seems pretty straightforward:

    tabstat `survey_items', stat(n mean sd) save
    return list
    matrix desc_stats = r(StatTotal)'
    matlist desc_stats
    putexcel set "${table_location}/Descriptive_statistics.xlsx", sheet("Sheet1") replace
    putexcel A1= matrix(desc_stats), names overwritefmt

    But I can't figure out how to generate a matrix with the same descriptive statistics for the imputed data. "misum" generates the statistics, but I am having difficulty making the matrix command work; the matrix is empty:

    mi convert flong, clear
    misum `survey_items'
    matrix mi_desc_stats = r(StatTotal)'
    matlist mi_desc_stats

    This is what the last three commands output in the results window:

    . misum `farmimp_items'

    m=1/5 data

    Variable | Mean SD min max N
    -------------+-------------------------------------------------------
    var1 | 2.719593 1.086147 .45611 5.109824 881
    var2 | 2.949962 1.040069 .3450429 5.469518 881
    var3 | 2.568165 1.140307 -.7103254 5.74613 881
    var4 | 2.737817 .9577713 .6009374 4.83914 881
    var5 | 3.478526 .7357405 1 5.017073 881
    (etc. etc.)

    . matrix mi_desc_stats = r(StatTotal)'

    . matlist mi_desc_stats

    | c1
    -------------+-----------
    r1 | .

    Can anyone suggest what I might be doing wrong?

    Best,
    Ethan









  • #2
    Can you post some sample data?

    Comment


    • #3
      Hi Andrew -- Thank you for reply. Sorry it took me a few days to respond. I ended up figure out how to do it, I think, using the code below.

      *Descriptive statistics, observed data only
      *Here the dataset pre-imputation is used, but the same results would be obtained post-imputation using "mi xeq 0:"
      tabstat `survey_items', stat(n mean sd) save
      return list
      matrix desc_stats = r(StatTotal)'
      matlist desc_stats
      putexcel set "${table_location}/Descriptive_statistics.xlsx", sheet("Descriptive statistics") replace
      putexcel A3= "Observed data only" A4= matrix(desc_stats), names overwritefmt

      *Descriptive statistics, including imputed data
      *Results are added to excel spreadsheet created above, so means pre- and post-imputation can be compared
      mi convert flong, clear
      misum `survey_items', mat(mi_desc_stats)
      matlist r(mi_desc_stats)
      putexcel set "${table_location}/Descriptive_statistics.xlsx", sheet("Descriptive statistics") modify
      putexcel F3= "Imputed data" F4= matrix(r(mi_desc_stats)), names overwritefmt

      My attention was also drawn to a forum post in which the author of misum raises questions about its usefulness, given that mi was not designed with descriptive statistics in mind. However, given that the variable means for data that include imputed values can be calculated, across imputations, using Rubin's rules, I think it is useful to offer a table that shows the means of variables, and their standard deviations from the mean, pre- and post-imputation, along with the observed n for each variable and the number of observations with imputed values. That's what the table above is intended to do.

      Comment

      Working...
      X