Announcement

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

  • mi estimate with estimates use

    Dear Statalists,

    I have 50 estimation results stored in mi_nlcom.ster.
    The estimation results are from calculating results with nlcom on 50 multiply imputed datasets:
    Code:
    estimates save "mi_nlcom", append
    I wish to combine these results with Rubin's rule using "mi estimate" and am wondering if the following code produces the right results:
    Code:
    mi estimate, cmdok: estimates use "mi_nlcom.ster"
    I get a table that appears to be correct. That is, they are not replications of any of the 50 nlcom results but entirely new, but I don't know how I would go about figuring out if these coefficients are correctly combined so I ask here if my understanding of the code itself is correct?

    PS: using this code gets me an error:
    Code:
    mi estimate using "mi_nlcom.ster"
    "corrupt MI estimation file"
    Best,
    Wei

  • #2
    I found a solution that I am more confident produces the correct results.
    It might be inelegant, but works.

    Code:
    use "MI_imputed_dataset.dta"
    mi set wide
    
    global minum 0
    program miresults, eclass properties(mi)
        global minum = $minum + 1
        estimates use "mi_nlcom.ster", number($minum)
    end
    
    mi estimate, cmdok: miresults
    1. Load and mi set my MI dataset.
    2. Create a program that gets each result from the .ster file sequentially via a global counting macro. (Results are already correctly stored in e(b), e(V) etc. in my case)
    3. Run program through mi estimate, cmdok:, relying on my MI dataset for retrieving correct number of results from the imputed data.

    I call it inelegant since I don't need the MI dataset, but use it for informing mi estimate the number of imputed datasets/results in the .ster. And someone will probably chew me out for the use of a global macro... inside a program no less.

    Please let me know if this looks off to you.

    Happy coding!

    Comment


    • #3
      I am having trouble understanding where you are coming from. How did you store the results in the file mi_nlcom.ster in the first place?

      You should have typed something like:

      Code:
      mi estimate (name: exp) : estimation_command ...
      where exp is the expression for nlcom. After that mi estimate should immediately report the correct nlcom results. See Example 5 in [MI] mi estimate.

      Comment


      • #4
        I haven't used mi estimate directly because I am bootstrapping a gsem model within each multiply imputed dataset. Since I can't wrap mi estimate: bootstrap: gsem, I have had to write a program for bootstrap:gsem. Which I then put into mi estimate, cmdok: bootstrappedgsem.
        Therefore within the program I compute the nonlinear combinations with nlcom, which is then combined by mi estimate.
        This I already did and obtained what I assume are correctly combined estimates.

        My question was partly out of curiosity. Since I stored each of the 50 nlcom results in a single .ster file, would it be possible to combine these and get the same result without running the whole gsem again... which would be very timeconsuming considering I bootstrap 500 replications...
        I also have a file with the 50 gsem results that I don't get an output on since mi estimate only combines what is last stored in the e-class values. These I can now also combine and get a result on through the way I did it above.

        Hope this answers your question?

        Comment


        • #5
          I think the approach in #2 should generally work. It's quite a hack, though. For example, if the number of imputations in the loaded dataset is less than the number of results stored in the ster-file (minus 1 because the last results are the combined ones from mi) you probably won't easily notice.

          Also, I wonder, why you need to mi set the imputed dataset. Should it not already be mi set?

          Comment


          • #6
            You're right, there was no need to mi set. I thought mi estimate needed to know the format of the data to run but I tried and it works just fine without it.
            Thanks.

            And yes, it is definitely a hack... It works for my specific case but would easily break or produce wrong results with no way of knowing.
            I compared results with what came directly out of mi estimate, cmdok: myprogram and they match. Doing the same for the GSEM should then produce correct results too.

            Comment


            • #7
              As a follow up question.

              Any idea if mi estimate ​​​​​​creates a macro or something for which imputation number it is currently "processing"? So that I could replace the global macro with something in-built.

              Comment


              • #8
                Originally posted by Wei Hai Deng View Post
                Any idea if mi estimate ​​​​​​creates a macro or something for which imputation number it is currently "processing"?
                It probably does; my guess is that this is wired into Mata. Anyway, it is not documented and probably not easily accessible.

                I would not worry too much about the global if that code was in a single do-file. If you were worried, use a name that is unlikely to be used by someone else, think

                Code:
                global A_nAMe__NobOdy___WouLd_use 0

                Comment


                • #9
                  Good idea. I'll use that next time I make a sketchy code I want to keep from infecting the rest of my analyses.

                  Thank you for the help Daniel.

                  Comment

                  Working...
                  X