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]

Re: st: Re: Input data from keyboard combined with Monte Carlo


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Re: Input data from keyboard combined with Monte Carlo
Date   Wed, 19 Jun 2013 17:58:15 +0100

-sim- has an option but you do not supply it an argument. In a
nutshell, -simulate- calls -sim- which expects an option, but where is
it provided?

This is reminiscent of a thread recently started by Chris Aberson on
Statalist, but then seemingly abandoned.

Jump to Maarten Buis's answer at

http://stackoverflow.com/questions/17156909/user-program-not-recognized-by-simulate-command-in-stata

Your problem may be inside out, perhaps you need to call -simulate-
_within_ your program, in which case you need two programs, not one.
Again, see Maarten's code and discussion.


Nick
[email protected]


On 19 June 2013 17:41, John Antonakis <[email protected]> wrote:
> Thanks Joseph.
>
> Seems that your suggestion fits the bill; however, I can't get it work.  I
> have tried:
>
> capture program drop sim
> version 12.1
> program define sim, rclass
> syntax , data.dta(string)
> drop _all
>
> use "`data.dta'"
>
> set obs 111
>
> foreach var of newlist x1-x5 {
> gen `var' = rnormal()
> }
> reg y x*
>
> end
>
> simulate explvar=e(r2), reps(50) seed(123): sim
>
> Can you see where the problem is?
>
> Best,
> J.
>
>
>
> __________________________________________
>
> John Antonakis
> Professor of Organizational Behavior
> Director, Ph.D. Program in Management
>
> Faculty of Business and Economics
> University of Lausanne
> Internef #618
> CH-1015 Lausanne-Dorigny
> Switzerland
> Tel ++41 (0)21 692-3438
> Fax ++41 (0)21 692-3305
> http://www.hec.unil.ch/people/jantonakis
>
> Associate Editor
> The Leadership Quarterly
> __________________________________________
>
> On 19.06.2013 13:40, Joseph Coveney wrote:
>> John Antonakis wrote:
>>
>> Suppose that I want to run the below program.
>>
>> [omitted]
>>
>> Now I want to generate y by using fixed-values that I input, e.g.,
>>
>> input y
>> [omitted]
>> end
>>
>> How can I combine inputting the data within the MC program so that the
>> y-values are always fixed and that the x's are randomly generated?
>>
>>
>> --------------------------------------------------------------------------------
>>
>> You could do this by first putting in your fixed y-values in a Stata file,
>> and
>> then feeding the file name to your simulation program so that it can -use-
>> it.
>> I've shown an example of the approach below.  Although I've shown it using
>> a
>> permanent file in the present working directory, my suggestion is to use
>> -tempfile- if it's possible.  If your -tempfile- directory has spaces in
>> the
>> path, then be sure to surround it with double quotation marks.
>>
>> Joseph Coveney
>>
>> version 12.1
>>
>> clear *
>> set more off
>>
>> program define sim, rclass
>>     version 12.1
>>     syntax , file(string)
>>
>>     drop _all
>>     use "`file'"
>>     foreach var of newlist x1-x5 {
>>         generate double `var' = rnormal()
>>     }
>>     regress y x*
>> end
>>
>> /* Now I want to generate y by using fixed-values that I input */
>>
>> input y
>> 4.715581
>> 4.296504
>> 4.170745
>> 2.065717
>> 3.648136
>> 8.156727
>> 2.280866
>> 2.817171
>> 2.647611
>> 3.272532
>> end
>>
>> quietly save myfile
>>
>> simulate explvar=e(r2), reps(50) seed(123): sim , file(myfile)
>> list in 1/5, noobs separator(0)
>>
>> /* Now I want to generate y by using fixed-values that I input, Take 2 */
>>
>> drop _all
>> input y
>> 0.8089706
>> 0.7720405
>> 1.9218385
>> 0.58947305
>> 1.5778341
>> 0.5398982
>> 1.142306
>> 0.50413711
>> 0.23358981
>> 0.24074392
>> 0.6785751
>> end
>>
>> quietly save myfile, replace
>>
>> simulate explvar=e(r2), reps(50) seed(123): sim , file(myfile)
>> list in 1/5, noobs separator(0)
>>
>> erase myfile.dta
>>
>> exit
>>
>>
>> *
>> *   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/
>
> *
> *   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/
*
*   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