Announcement

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

  • Simulate Comman

    I'm trying to pull model fit statistics from an SEM. To do this I'm using a loop and the following simulate command.
    simulate chi2=e(chi2_ms) df=e(df_ms) chi2p=e(p_ms), reps(10) :fitstat
    Fitstat is a method that sets up the parameters needed for the project.

    My question is, can I use the simulate command as I do above to pull the error covariance from the same simulation?

  • #2
    simulate is a wrapper command for any program that uses random samples to produce (usually different) runs of some stochastic or probabilistic process. But fitstat (SSC etc.) is just a deterministic program that reports on goodness of fit. If you run it repeatedly it should produce exactly the same results, just as repeating the calculation 2 + 2 should give you 4 every time. Far from setting up initial conditions for any simulation project, fitstat sits downstream of any model fit.

    Otherwise put, simulate does not itself simulate; it couldn't do that in general without instructions because different simulations require quite different random number generation. It is the job of the program called to set that up. The help does give a detailed example.

    I can't advise positively because I don't know exactly what would make sense for your SEM. I think even SEM experts would need more details on what you are fitting; indeed I can't see that you say anything about that.
    Last edited by Nick Cox; 31 May 2016, 13:46.

    Comment


    • #3
      Here is the for loop I'm using.

      forvalues j= .00(.02).2 {
      global cov_x5x6 = `j'
      simulate chi2=e(chi2_ms) df=e(df_ms) chi2p=e(p_ms), reps(10) :fitstat
      capture confirm file "C:\Users\wbellam\Desktop\RA Files\fitstat_test.csv"
      if _rc==0 {
      outsheet (chi2 df chi2p $j ) using "C:\Users\wbellam\Desktop\RA Files\temp-fitstat_test.csv", nonames replace
      appendfile "C:\Users\wbellam\Desktop\RA Files\temp-fitstat_test.csv" "C:\Users\wbellam\Desktop\RA Files\fitstat_test.csv"
      }
      else {
      outsheet (chi2 df chi2p $j ) using "C:\Users\wbellam\Desktop\RA Files\fitstat_test.csv"
      }

      }

      And the rest of the program

      program drop _all
      global simreps 1000
      global simobs 1000
      program define fitstat, rclass
      drop _all
      //set obs 1000
      set more off
      capture { //set up true model
      global rho = .7 //
      matrix Sig = (1,$rho,$rho,$rho,$rho,$rho \ $rho,1,$rho,$rho,$rho,$rho \ $rho,$rho,1,$rho,$rho,$rho \ $rho,$rho,$rho,1,$rho,$rho \ $rho,$rho,$rho,$rho,1,$rho \ $rho,$rho,$rho,$rho,$rho,1 )
      matrix m = (0 , 0 , 0 , 0 , 0 , 0)
      matrix sd = (1 , 1 , 1 , 1 , 1 ,1)
      drawnorm x1 x2 x3 x4 x5 x6, n($simobs) corr(Sig) means(m) sds(sd)
      //matrix of four variables, mean zero, sd 1, correlations = $rho
      }
      corr
      sem (Trait -> x1 x2 x3 x4 x5 x6) // true model
      sem (Trait -> x1 x2 x3 x4 x5 x6), cov(e.x5*e.x6@$cov_x5x6) //less true model

      end

      the "global cov_x5x6 = `j'" part doesn't work, that was the method my professor tried to see if it could pull the error covariance and output it. This loop pulls the chi2, df, and p value for chi2 and outputs it to an Excel file which then appends a master file. There's got to be a place where Stata temporarily stores the output from a SEM. I used the ereturn list command to find the location of the 3 other items I'm looking for, but I can't figure out where Stata stores the error covariance. Is that more helpful?

      Comment

      Working...
      X