Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Joseph Coveney" <stajc2@gmail.com> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | st: Re: Input data from keyboard combined with Monte Carlo |
Date | Wed, 19 Jun 2013 20:40:38 +0900 |
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/