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: Input data from keyboard combined with Monte Carlo


From   John Antonakis <[email protected]>
To   [email protected]
Subject   Re: st: Input data from keyboard combined with Monte Carlo
Date   Wed, 19 Jun 2013 19:49:24 +0200


Thanks for the idea. Thread closed--hope this solutions helps others (actually I did not look at your paper yet, Nick, but I will).

So, I basically used mkmat to save the data to a matrix, then I retrieved the data with svmat and it works, like this:

set more off

use "C:\My documents\STATA\data.dta", clear
mkmat y

capture program drop sim
version 12.1
program define sim, rclass
drop _all

set obs 111

svmat y, names(y)

foreach var of newlist x1-x17 {
gen `var' = rnormal()
}


reg y1 x*

end

simulate e(r2) e(F), reps(5000) seed (123) : sim

set more on


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 19:11, Nick Cox wrote:
> You are quite correct. Thanks!
>
> The matrix solution was one I mentioned earlier in the thread. There
> is a kind of riff on the idea within
>
> http://www.stata-journal.com/article.html?article=pr0054
>
> Nick
> [email protected]
>
>
> On 19 June 2013 17:54, Austin Nichols <[email protected]> wrote:
>> Nick--
>> A -program- cannot include -input- because -end- is ambiguous. Easy
>> enough to put the data in a matrix, which the program turns into a
>> variable.
>>
>> On Wed, Jun 19, 2013 at 12:50 PM, Nick Cox <[email protected]> wrote:
>>> I see. If n is not fixed, the -display- directive to input numbers
>>> would need to be supplemented by input of how many numbers you intend
>>> to give, which probably rules it out.
>>>
>>> I don't see why your program should not allow -input- in the middle,
>>> but I've not tried that, or at least recently. Seems easiest to input
>>> some numbers, then run the program.
>>> Nick
>>> [email protected]
>>>
>>>
>>> On 19 June 2013 17:42, John Antonakis <[email protected]> wrote:
>>>> Hi Nick:
>>>>
>>>> Thanks for your suggestions.
>>>>
>>>> The n=11 was just indicative....I did not want to have a wieldy example.
>>>>
>>>> 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 12:36, Nick Cox wrote:
>>>>> You perhaps don't want to hear the advice not to do that, but
>>>>> -display- has a _request() directive that is one way to do it.
>>>>>
>>>>> Even if you're the only user, either you'll crash this repeatedly with
>>>>> silly little errors or you'll spend time writing code to catch such
>>>>> errors. Perhaps you don't mind.
>>>>>
>>>>> With 11 as the sample size, I'd consider typing them as a Stata matrix
>>>>> (vector) or as a numlist in an option. The two can be combined.
>>>>>
>>>>> Nick
>>>>> [email protected]
>>>>>
>>>>>
>>>>> On 19 June 2013 11:20, John Antonakis <[email protected]> wrote:
>>>>>> Suppose that I want to run the below program.
>>>>>>
>>>>>> clear
>>>>>> capture program drop sim
>>>>>> version 12
>>>>>> program define sim, rclass
>>>>>> drop _all
>>>>>> set obs 11
>>>>>> foreach var of newlist x1-x5 {
>>>>>> gen `var' = rnormal()
>>>>>> }
>>>>>> reg y x*
>>>>>> end
>>>>>> simulate explvar=e(r2), reps(50) seed(123): sim
>>>>>>
>>>>>> Now I want to generate y by using fixed-values that I input, e.g.,
>>>>>>
>>>>>> input y
>>>>>> 4.715581
>>>>>> 4.296504
>>>>>> 4.170745
>>>>>> 2.065717
>>>>>> 3.648136
>>>>>> 8.156727
>>>>>> 2.280866
>>>>>> 2.817171
>>>>>> 2.647611
>>>>>> 3.272532
>>>>>> 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?
> *
> *   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