Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Confusion about using Stata local variables in Mata, the -st_local- function and the -stata- command


From   Milen Stoyanov <[email protected]>
To   [email protected]
Subject   st: Confusion about using Stata local variables in Mata, the -st_local- function and the -stata- command
Date   Sun, 10 Nov 2013 15:32:21 +0200 (EET)

I have a dataset that I have created in Mata and then exported to Stata. I am creating the dataset in a loop, so that on each iteration the dataset is different. I would like to save each of those datasets, so what I am trying to do is the following:

mata
    for (i=1;i<=d;i++) {
        "generate dataset"
        "export to Stata"
        .....
        st_local("counter",  strofreal(i))
        stata(`"save "Temp\temp_`counter'.dta", replace"')
    }
end

I am having no troubles with my first 2 steps, which are "generate dataset" and "export to Stata", that is why I am only indicating that there is such kind of code, but it is long and I don't believe it is important for this particular question of mine. 

So I am trying to save a new dataset of the form "temp_`counter'.dta" each time, where counter is going from 1 to about a 1000. In the end I was hoping to get files "temp_1.dta", "temp_2.dta", ... "temp_1000.dta" in my folder. I think that the line "st_local("counter",  strofreal(i))" works fine and it defines the local variable correctly, but then the save command in stata does not work as intended by me. So what happens in the end is that the loop does not break or give an error message, but each single time it saves over the file "temp_.dta", so it ignores the counter whatsoever.

Does anyone has an idea how I might make this work? Thanks for the help in advance.
        
        
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index