Announcement

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

  • Saving multiple file names in one .txt or .dat


    Dear all, I would like to run Monte Carlo simulation in Mplus using 100 data generated from Stata. To do so, I first need one master file that lists all file names.

    For instance, in .txt or .dat file (i.e. replist), file names should be listed as follows:


    m1.dat
    m2.dat
    ...
    m9.dat
    m10.dat
    ...
    m100.dat


    I can easily generate 100 data and convert into .dat format using the following code. Yet, I have not find a way to save 100 file names in one .txt or. dat format. Please note that I need to run my models in Mplus not in Stata, and the original data generation code is more complex.

    Your advice will be greatly appreciated.




    Sean





    Code:
    forval q = 1/100 {
    clear all
    
    global obs        = 500        
    global waves     = 5           
    
    global corrXY    = .5    
    global corrXZ     = 0      
    global corrYZ     = 0    
    
    mat C =(1, $corrXY,$corrXZ \ $corrXY,1,$corrYZ \ $corrXZ,$corrYZ,1)
    corr2data X Y Z, n($obs) corr(C)
    
    save "m`q'", replace
    stata2mplus using "m`q'", replace
    }

  • #2
    Perhaps this example will start you in a useful direction.
    Code:
    . clear
    
    . set obs 100
    number of observations (_N) was 0, now 100
    
    . generate str20 filename = ""
    (100 missing values generated)
    
    . forval q = 1/100 {
      2. quietly replace filename = "m`q'.dat" in `q'
      3. }
    
    . outfile filename using "myfilenames.txt", noquote replace
    
    . type myfilenames.txt, lines(5)
    m1.dat
    m2.dat
    m3.dat
    m4.dat
    m5.dat
    .

    Comment


    • #3
      This works great! Thanks so much William. Appreciate that.

      Sean

      Comment

      Working...
      X