Announcement

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

  • Issue with MICE - The imputation runs, but there are still missing variables in the datasets.

    Hi all,

    I'm having issues with multiple imputation using chained equations. I've done this several times in the past with the same data, but I 've been having issues after going back to a file earlier in the cleaning process and changing the operationalization of a race var.

    I do not receive an error message, but the imputation is not completed and the missing values are still present. I've done some research in other places and can't figure out why this is happening now.

    My missingess is pretty low for the vars of interest <5% , but I'm still choosing to impute. I'm imputing the race categorical vars using (regress), because otherwise I do not achieve convergence. I clean them back into their categories after imputing. I tried imputing a different dataset and tried using older files (that worked last) and I still get incomplete imputations. I also tried on a different computer and have the same issue. At first I thought the issue was my computer/Stata installation, but now I'm wondering if the files are corrupted? I'm truly at a loss as to why imputing doesn't work.

    I will include sample data and code below:

    Any help is much appreciated,

    EDIT: Fixed the formatting so the code below is appropriately formatted

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float id str2 stfips str5 scfips int year float(school location assault otheroff offtotal offage offrace1 offrace2 vtotal vage vsex vrace1 vrace2 female vfemale)
      1 "01" "01073" 2015 0 3 1 0 2 21.5 2 2  5   15 0 2 2 0 1
      2 "01" "01073" 2017 0 2 1 0 4 18.5 3 3  1   28 1 1 1 0 0
      3 "01" "01073" 2017 0 2 1 0 1   20 2 2  1   18 1 2 2 0 0
      4 "01" "01073" 2017 0 3 1 0 1   16 2 2  1   17 1 2 2 0 0
      5 "01" "01073" 2016 0 2 1 1 2 19.5 2 2  2 32.5 1 4 4 0 0
      6 "01" "01073" 2017 0 2 1 0 1   20 2 2  2   19 1 2 2 0 0
      7 "01" "01073" 2016 0 3 1 0 2   21 2 2  3   44 0 2 2 1 1
      8 "01" "01073" 2019 0 2 1 1 2   18 2 2  2   16 1 2 2 0 0
      9 "01" "01073" 2016 0 3 1 0 1   24 2 2  1   10 1 2 2 0 0
     10 "01" "01073" 2017 0 2 1 0 4 18.5 3 3  1   64 0 1 1 0 1
     11 "01" "01073" 2016 0 3 1 0 2   18 2 2  1   21 1 2 2 0 0
     12 "01" "01073" 2015 0 3 1 1 2   19 2 2  1   37 1 1 1 0 0
     13 "04" "04013" 2019 0 3 1 2 2   19 2 2  3   18 0 2 2 0 1
     14 "04" "04013" 2019 0 3 1 0 1   22 1 1  2 10.5 0 4 4 0 1
     15 "04" "04013" 2019 0 2 1 2 1   19 1 1  2   43 1 3 3 0 0
     16 "04" "04013" 2019 0 2 1 1 1   20 1 1  5 35.5 0 1 1 0 1
     17 "04" "04013" 2018 0 2 1 1 6   18 3 2  2   17 1 1 1 0 0
     18 "04" "04013" 2017 0 2 1 2 1   18 2 2  3 38.5 0 3 3 0 1
     19 "04" "04013" 2018 0 3 1 0 2   18 1 1  2   18 1 1 1 0 0
     20 "04" "04013" 2018 0 2 1 1 1   22 1 1  2   25 0 3 3 0 1
     21 "04" "04013" 2019 0 2 1 1 1   22 2 2  2   17 0 1 1 0 1
     22 "04" "04013" 2016 0 2 1 1 1   20 1 1  2   18 1 1 1 0 0
     23 "04" "04013" 2019 0 3 1 2 2 19.5 3 3  3 19.5 1 1 1 0 0
     24 "04" "04013" 2015 0 2 1 0 2   20 3 1  2 39.5 0 1 1 1 1
     25 "04" "04013" 2019 0 2 1 0 1   24 1 1  1   53 0 1 1 0 1
     26 "04" "04013" 2019 0 2 1 2 5   16 3 1  3 25.5 1 1 1 0 0
     27 "04" "04013" 2019 0 2 1 0 1   23 2 2  1   27 1 1 1 0 0
     28 "04" "04013" 2015 0 2 1 1 1   17 2 2  1   16 0 3 3 0 1
     29 "04" "04013" 2017 0 2 1 1 2   22 3 1  3   29 0 4 4 0 1
     30 "04" "04013" 2016 0 2 1 0 1   17 2 2  1   27 1 1 1 0 0
     31 "04" "04013" 2019 0 2 1 0 1   15 1 1  1   13 1 1 1 0 0
     32 "04" "04013" 2017 0 2 1 0 1   19 2 2  1   14 1 2 2 0 0
     33 "04" "04013" 2018 0 2 1 1 1   15 1 1  6   21 0 1 1 0 1
     34 "04" "04013" 2015 0 2 1 0 1   22 1 1  2   26 1 1 1 0 0
     35 "04" "04013" 2016 0 2 1 0 1   16 1 1  1   12 1 1 1 0 0
     36 "04" "04013" 2017 0 2 1 0 2 15.5 1 1  1   14 1 1 1 0 0
     37 "04" "04013" 2018 0 3 1 1 1   18 1 1  2   25 0 4 4 1 1
     38 "04" "04013" 2015 0 2 1 2 3   18 1 1  4   16 1 4 1 0 0
     39 "04" "04013" 2016 0 3 1 0 1   24 1 1  1   23 1 1 1 0 0
     40 "04" "04013" 2015 1 1 1 0 1   20 2 2  1   17 1 1 1 0 0
     41 "04" "04021" 2017 0 3 1 0 1   20 1 1  1   19 0 . . 0 1
     42 "04" "04021" 2016 0 3 1 0 2   13 . .  2   15 1 1 1 0 0
     43 "04" "04021" 2017 0 3 1 0 3   19 3 1  2 17.5 0 1 1 1 1
     44 "04" "04021" 2019 0 3 1 0 1   22 1 1  1   28 0 1 1 0 1
     45 "04" "04021" 2017 0 2 1 0 1   15 . .  1   15 1 1 1 0 0
     46 "04" "04021" 2016 0 3 1 0 1   21 1 1  1   38 1 1 1 0 0
     47 "04" "04021" 2016 0 3 1 1 1   23 1 1  2 23.5 0 1 1 1 1
     48 "04" "04021" 2017 0 2 1 1 5 14.5 3 1  2   20 1 2 2 1 0
     49 "04" "04021" 2019 0 3 1 1 1   24 1 1  2   12 1 3 3 0 0
     50 "04" "04021" 2019 0 2 1 0 1   15 2 2  1   35 1 2 2 0 0
     51 "04" "04021" 2018 0 3 1 4 1   20 . .  3 34.5 0 1 1 0 1
     52 "04" "04021" 2019 0 2 1 0 1   24 1 1  1   57 1 1 1 0 0
     53 "04" "04021" 2015 0 3 1 1 2   23 3 1  3   25 0 1 1 0 1
     54 "04" "04021" 2018 0 2 1 0 1   18 1 1  3   20 0 1 1 1 1
     55 "04" "04027" 2017 0 3 1 2 1   20 1 1  3   19 0 1 1 0 1
     56 "04" "04027" 2017 0 2 1 1 2   22 3 1  2   47 0 3 3 1 1
     57 "04" "04027" 2019 0 2 1 1 1   20 1 1  2   31 1 2 2 0 0
     58 "04" "04027" 2019 0 3 1 1 1   22 1 1  5   36 0 4 3 0 1
     59 "04" "04027" 2018 0 2 1 0 1   22 1 1  4   34 0 3 3 0 1
     60 "04" "04027" 2018 0 2 1 3 4   20 3 3  2   21 0 3 3 0 1
     61 "04" "04027" 2019 0 2 1 0 2   23 3 3  1   23 1 3 3 0 0
     62 "04" "04027" 2017 0 3 1 3 1   24 1 1  2   50 0 3 3 0 1
     63 "04" "04027" 2015 0 3 1 0 1   21 2 2  4   19 0 4 3 0 1
     64 "04" "04027" 2016 0 3 1 1 1   21 3 3  1   11 1 3 3 0 0
     65 "04" "04027" 2015 0 2 1 0 2   21 1 1  2   18 1 4 4 0 0
     66 "04" "04027" 2015 0 3 1 2 1   13 1 1  2   14 1 3 3 0 0
     67 "04" "04027" 2015 0 2 1 0 2   22 3 1  1    . 1 1 1 0 0
     68 "04" "04027" 2016 0 2 1 0 1   24 2 2  1   34 1 3 3 0 0
     69 "04" "04027" 2019 0 3 1 1 1   23 1 1  2   22 1 3 3 0 0
     70 "04" "04027" 2016 0 2 1 1 1   21 1 1  8   17 0 1 1 0 1
     71 "04" "04027" 2017 0 2 1 1 1   21 1 1  2   21 1 1 1 0 0
     72 "04" "04027" 2018 0 2 1 0 2   18 1 1  1   19 0 3 3 0 1
     73 "04" "04027" 2017 0 3 1 1 1   24 1 1  2   41 0 3 3 0 1
     74 "04" "04027" 2016 0 2 1 1 1   24 1 1  3    . 1 1 1 0 0
     75 "04" "04027" 2015 0 2 1 0 1   24 1 1  3    8 0 3 3 0 1
     76 "04" "04027" 2019 0 3 1 0 1   14 1 1  1   12 1 3 3 0 0
     77 "04" "04027" 2017 0 2 1 1 3   22 1 1  2   54 1 4 4 0 0
     78 "04" "04027" 2017 0 3 1 0 1   20 1 1  1   20 0 1 1 0 1
     79 "04" "04027" 2018 0 3 1 1 1   18 1 1  1   21 1 3 3 0 0
     80 "04" "04027" 2015 0 3 1 1 1   19 1 1  2   27 0 3 3 0 1
     81 "04" "04027" 2015 0 2 1 0 2   17 3 3  1   30 0 4 4 0 1
     82 "04" "04027" 2019 0 3 1 1 1   23 1 1  2   24 0 3 3 0 1
     83 "04" "04027" 2015 0 3 1 0 4   20 3 1  1   22 1 3 3 0 0
     84 "04" "04027" 2019 0 3 1 1 4 20.5 3 1  1   29 1 3 3 0 0
     85 "04" "04027" 2015 0 3 1 0 1   19 1 1  1   50 0 3 3 0 1
     86 "04" "04027" 2018 0 2 1 2 2   23 3 1  3   45 0 3 3 0 1
     87 "04" "04027" 2017 0 2 1 3 5   22 3 1  3   22 1 2 2 1 0
     88 "04" "04027" 2016 0 2 1 1 2   19 3 1  2   15 1 3 3 0 0
     89 "04" "04027" 2015 0 2 1 0 1   22 1 1  1   33 1 3 3 0 0
     90 "04" "04027" 2018 0 3 1 3 7   18 3 1 48   55 0 4 3 0 1
     91 "04" "04027" 2017 0 2 1 1 2   23 3 1  2   45 1 1 1 0 0
     92 "04" "04027" 2018 0 2 1 1 1   19 1 1  2   23 1 3 3 0 0
     93 "04" "04027" 2017 0 2 1 1 1   21 2 2  2   22 1 2 2 0 0
     94 "04" "04027" 2015 0 3 1 0 1   23 1 1  4 34.5 0 3 3 0 1
     95 "04" "04027" 2016 0 2 1 1 1   21 1 1  2   24 1 3 3 0 0
     96 "04" "04027" 2016 0 3 1 0 1   15 1 1  1   80 0 3 3 0 1
     97 "04" "04027" 2018 0 2 1 1 1   23 1 1  4   17 0 3 3 0 1
     98 "04" "04027" 2018 0 3 1 1 1   19 2 2  2   46 1 3 3 0 0
     99 "04" "04027" 2015 0 2 1 0 1   21 1 1  1   40 1 3 3 0 0
    100 "04" "04027" 2019 0 3 1 3 1   23 1 1  3   22 0 1 1 0 1
    end
    label values location p_location
    label def p_location 1 "School", modify
    label def p_location 2 "Public", modify
    label def p_location 3 "Home", modify
    label values offrace1 p_offrace
    label values offrace2 p_offrace
    label def p_offrace 1 "White", modify
    label def p_offrace 2 "Black", modify
    label def p_offrace 3 "Other", modify
    label values vsex p_vsex
    label def p_vsex 0 "at least one female", modify
    label def p_vsex 1 "male", modify
    label values vrace1 p_vrace1
    label values vrace2 p_vrace1
    label def p_vrace1 1 "Non-Hispanic White", modify
    label def p_vrace1 2 "Non-Hispanic Black", modify
    label def p_vrace1 3 "Hispanic", modify
    label def p_vrace1 4 "Other", modify
    label values female female
    label def female 0 "Male", modify
    label def female 1 "At least one female", modify
    label values vfemale vfemale
    label def vfemale 0 "Male", modify
    label def vfemale 1 "At least one female", modify
    Code:
    destring stfips, replace
    destring scfips, replace
    mi set flong
    mi register regular id stfips scfips year school location assault otheroff offtotal offage  vtotal
    mi register imputed female offrace1 offrace2 vage vfemale vrace1 vrace2
    mi impute chained (logit) female (regress) offrace1 (regress) vage (logit) vfemale (regress) vrace1 = location offage stfips year otheroff offtotal vtotal  , add(10) rseed (54321) savetrace(trace1, replace)

    Last edited by Kevin Knight; 22 Jan 2023, 15:47.

  • #2
    there are some oddities in your command, including: (1) stfips is a string variable and cannot be used as a predictor as you have tried; (2) you are attempting use -regress- on variables that are categorial with small numbers of categories (offrace1 and vrace2) without using factor variable notation - you say you fail to converge with other forms of imputation for these but ... - at any rate, given the first point I don't see how anything runs - but you say you don't get any error message which is very unexpected

    Comment


    • #3
      Thanks for the comment. I made sure to destring stfips prior to registering it and including it as a predictor. I'll try running the imputation with mlogit for the categorical variables- I think I tried this early and ended up with incomplete imputations. I'm rather confused as I have run this several times with no problem in the past.

      Comment


      • #4
        [SOLVED] I reinstalled Stata and got it to work. Note sure what happened. Rich, thank you for the feedback on the model itself. I will keep this in mind when I am testing my model tomorrow.

        Comment

        Working...
        X