Statalist


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

Re: st: Re: Monte Carlo Simulation, help!


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   Re: st: Re: Monte Carlo Simulation, help!
Date   Sun, 18 Jan 2009 21:13:19 +0100

As I said earlier, if you want to vary parameters of the -simulate- call, use -foreach-. To capture the output after the call, you must insert something like -postfile-, otherwise each call will overwrite the prior one. In this respect, your final goal of your analysis is still opaque...


**********
loc cases 71 259 121 262 192 120

cap drop lnsim
di in red _rc

   program define lnsim, rclass
       version 10.1
       syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
       drop _all
       set obs `obs'
       tempvar z
       gen `z' = exp(rnormal(`mu',`sigma'))
       summarize `z'
       return scalar mean = r(mean)
       return scalar Var  = r(Var)
   end


   foreach ca of loc cases{
 simulate mean=r(mean) var=r(Var), reps(`ca'): lnsim, obs(100)
}
*********


HTH
Martin
_______________________
----- Original Message ----- From: "STATA Dndee" <[email protected]>
To: <[email protected]>
Sent: Sunday, January 18, 2009 8:59 PM
Subject: Re: st: Re: Monte Carlo Simulation, help!


Hi Martin

From your example I got this:

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       mean |       100     1272855     7417552   31.81747   6.60e+07
        var |       100    2.79e+15    2.22e+16   26013.05   2.17e+17


Thanks! finally I got something out of it.

I am trying to apply this to my data
    +-------------------------------------------------------+
    | inst   cases   total   outcome     lci     uci     sd |
    |-------------------------------------------------------|
 1. |    f      71     273    26.01%   20.8%   31.2%   2.7% |
 2. |    e     259     809    32.01%   28.8%   35.2%   1.6% |
 3. |    c     121     345    35.07%   30.0%   40.1%   2.6% |
 4. |    d     262     726    36.09%   32.6%   39.6%   1.8% |
 5. |    b     192     480    40.00%   35.6%   44.4%   2.2% |
    |-------------------------------------------------------|
 6. |    a     120     204    58.82%   52.1%   65.6%   3.4% |
 7. | mean     713    2153    33.12%   31.1%   35.1%   1.0% |

Should I remove the percentages? and run it for each Inst.
kind regards






--- On Sun, 18/1/09, Martin Weiss <[email protected]> wrote:

From: Martin Weiss <[email protected]>
Subject: Re: st: Re: Monte Carlo Simulation, help!
To: [email protected]
Date: Sunday, 18 January, 2009, 7:23 PM
BTW, your line "gen `z' = exp(`mu' +
`sigma'*invnorm(uniform())) " makes me think that
your Stata is either a not fully -update-d version 10 or
version 9 (or lower)?

HTH
Martin
_______________________
----- Original Message ----- From: "STATA Dndee"
<[email protected]>
To: <[email protected]>
Sent: Sunday, January 18, 2009 8:03 PM
Subject: Re: st: Re: Monte Carlo Simulation, help!


> Thank you Martin!
> I did that : "list" or looking at data
editor shows 10,000 empty rows!
>
> Kindest regards
>
>
>
> --- On Sun, 18/1/09, Martin Weiss
<[email protected]> wrote:
>
>> From: Martin Weiss <[email protected]>
>> Subject: Re: st: Re: Monte Carlo Simulation, help!
>> To: [email protected]
>> Date: Sunday, 18 January, 2009, 6:52 PM
>> Type -list- in Stata and you see your ouput
(10.000 rows, so
>> you may prefer
>> a -summarize-)
>>
>> HTH
>> Martin
>> _______________________
>> ----- Original Message ----- From: "STATA
Dndee"
>> <[email protected]>
>> To: <[email protected]>
>> Sent: Sunday, January 18, 2009 7:46 PM
>> Subject: Re: st: Re: Monte Carlo Simulation, help!
>>
>>
>> > Many thanks Martin and Carlo,
>> > You have already put a lot of time for this
thread.
>> >
>> > I tried:
>> >
>> > program define lnsim, rclass
>> >        version 9.2
>> >        syntax [, obs(integer 1) mu(real 0)
sigma(real
>> 1) ]
>> >        drop _all
>> >        set obs `obs'
>> >        tempvar z
>> >        gen `z' = exp(`mu' +
>> `sigma'*invnorm(uniform()))
>> >        summarize `z'
>> >        return scalar mean = r(mean)
>> >        return scalar Var  = r(Var)
>> >    end
>> >
>> >
>> > and then as in the stata hekp file example:
>> >
>> > simulate mean=r(mean) var=r(Var),
reps(10000): lnsim,
>> obs(50) mu(-3)
>> >        sigma(7)
>> >
>> >
>> > for each observation or for all of them no
error this
>> time but I got just
>> > rows like this(from 50 to 10,000):
>> >
>> > Simulations (10000)
>> > ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4
---+--- 5
>> >
.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> 50
>> >
>> > without any data output.
>> >
>> > Anyway, thank you again for your time.
>> > Kindest regards
>> >
>> >
>> >
>> >
>> > --- On Sun, 18/1/09, Martin Weiss
>> <[email protected]> wrote:
>> >
>> >> From: Martin Weiss
<[email protected]>
>> >> Subject: Re: st: Re: Monte Carlo
Simulation, help!
>> >> To: [email protected]
>> >> Date: Sunday, 18 January, 2009, 5:17 PM
>> >> This thread is getting weirder by the
minute:
>> StataDndee
>> >> seems to think that
>> >> Stata will read each line of this
dataset, and
>> enter his
>> >> information into
>> >> the -simulate- command. This is not going
to
>> happen. If you
>> >> want to enter
>> >> these values one after another and run
-simulate-,
>> look at
>> >> -help foreach-...
>> >>
>> >> HTH
>> >> Martin
>> >> _______________________
>> >> ----- Original Message ----- >>
From: "STATA Dndee"
>> >> <[email protected]>
>> >> To:
<[email protected]>
>> >> Sent: Sunday, January 18, 2009 5:47 PM
>> >> Subject: Re: st: Re: Monte Carlo
Simulation, help!
>> >>
>> >>
>> >> > Thanks dear Martin
>> >> > I tried that and got the same error.
Then
>> arranged the
>> >> data in data editor
>> >> > like this
>> >> >
>> >> >     +-----------------------+
>> >> >     | obs   mean        var |
>> >> >     |-----------------------|
>> >> >  1. |   1     71   .0007049 |
>> >> >  2. |   2    259    .000269 |
>> >> >  3. |   3    121     .00066 |
>> >> >  4. |   4    262   .0003177 |
>> >> >  5. |   5    192      .0005 |
>> >> >     |-----------------------|
>> >> >  6. |   6    120   .0011873 |
>> >> >     +-----------------------+
>> >> > and then this command with vluaes of
the mean
>> obs from
>> >> the last table:
>> >> >
>> >> > simulate mean=r(mean) var=r(Var),
>> reps(10000): lnsim,
>> >> obs(6) mu(713
>> >> > ) sigma(0.000102877)
>> >> >
>> >> > And got the same error
>> >> > loc not found
>> >> > an error occurred when simulate
executed
>> lnsim
>> >> > r(111);
>> >> >
>> >> > And that as before everything in
data editor
>> was gone.
>> >> there should be
>> >> > something with "lnsim" in
command.
>> >> >
>> >> > Thank you so much for your help.
>> >> >
>> >> >
>> >> > --- On Sun, 18/1/09, Martin Weiss
>> >> <[email protected]> wrote:
>> >> >
>> >> >> From: Martin Weiss
>> <[email protected]>
>> >> >> Subject: Re: st: Re: Monte Carlo
>> Simulation, help!
>> >> >> To:
[email protected]
>> >> >> Date: Sunday, 18 January, 2009,
3:55 PM
>> >> >> "loc not found" sounds
weird,
>> the real
>> >> trouble is
>> >> >> that you put a "%"
sign in
>> >> >> the "sigma"
specification. Just
>> put
>> >> 0.027
>> >> >> there...
>> >> >>
>> >> >> HTH
>> >> >> Martin
>> >> >> _______________________
>> >> >> ----- Original Message -----
>> >> From: "STATA Dndee"
>> >> >> <[email protected]>
>> >> >> To:
>> <[email protected]>
>> >> >> Sent: Sunday, January 18, 2009
4:50 PM
>> >> >> Subject: Re: st: Re: Monte Carlo
>> Simulation, help!
>> >> >>
>> >> >>
>> >> >> > Hi
>> >> >> >
>> >> >> > I have tried the following
commande:
>> >> >> >
>> >> >> > simulate mean=r(mean)
var=r(Var),
>> >> reps(10000): lnsim,
>> >> >> obs(100)
>> >> >> >
>> >> >> > from STATA help and for
Inst. F
>> >> >> >
>> >> >> > my command was:
>> >> >> > simulate mean=r(mean)
var=r(Var),
>> >> reps(10000): lnsim,
>> >> >> obs(273) mu(71)
>> >> >> > sigma(2.7%)
>> >> >> >
>> >> >> > and I got the following
error:
>> >> >> >
>> >> >> > loc not found
>> >> >> > an error occurred when
simulate
>> executed
>> >> lnsim
>> >> >> > r(111);
>> >> >> > When it resolved I should
run the
>> analysis
>> >> for all
>> >> >> INSs and the mean?
>> >> >> >
>> >> >> > the SE in the floowing
table was SD.
>> >> >> >
>> >> >> >
>> >> >> > I have copied the  table
again.
>> >> >> >
>> >> >> > Many thanks for any comment
>> >> >> > Bests
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >>
>>
+-------------------------------------------------------+
>> >> >> >     | inst   cases   total
 outcome
>>     lci
>> >>    uci
>> >> >>   sd |
>> >> >> >
>> >> >>
>> >>
>>
|-------------------------------------------------------|
>> >> >> >  1. |    f      71     273
  26.01%
>>   20.8%
>> >>  31.2%
>> >> >> 2.7% |
>> >> >> >  2. |    e     259     809
  32.01%
>>   28.8%
>> >>  35.2%
>> >> >> 1.6% |
>> >> >> >  3. |    c     121     345
  35.07%
>>   30.0%
>> >>  40.1%
>> >> >> 2.6% |
>> >> >> >  4. |    d     262     726
  36.09%
>>   32.6%
>> >>  39.6%
>> >> >> 1.8% |
>> >> >> >  5. |    b     192     480
  40.00%
>>   35.6%
>> >>  44.4%
>> >> >> 2.2% |
>> >> >> >
>> >> >>
>> >>
>>
|-------------------------------------------------------|
>> >> >> >  6. |    a     120     204
  58.82%
>>   52.1%
>> >>  65.6%
>> >> >> 3.4% |
>> >> >> >  7. | mean     713    2153
  33.12%
>>   31.1%
>> >>  35.1%
>> >> >> 1.0% |
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --- On Sun, 18/1/09, STATA
Dndee
>> >> >> <[email protected]>
wrote:
>> >> >> >
>> >> >> >> From: STATA Dndee
>> >> <[email protected]>
>> >> >> >> Subject: Re: st: Re:
Monte Carlo
>> >> Simulation, help!
>> >> >> >> To:
>> [email protected]
>> >> >> >> Date: Sunday, 18
January, 2009,
>> 1:20 PM
>> >> >> >> Thanks for your kind
and quick
>> reply
>> >> Martin
>> >> >> >>
>> >> >> >> I tried it before but
>> couldn't
>> >> understand the
>> >> >> commands
>> >> >> >> in Help file. I
arranged the
>> data with
>> >> the CIs.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >>
>> >>
>>
+-------------------------------------------------------+
>> >> >> >>      | inst   cases
total
>> outcome
>> >> lci
>> >> >> uci
>> >> >> >> se |
>> >> >> >>
>> >> >> >>
>> >> >>
>> >>
>>
|-------------------------------------------------------|
>> >> >> >>   1. |    f      71
273
>> 26.01%
>> >> 20.8%
>> >> >> 31.2%
>> >> >> >> 2.7% |
>> >> >> >>   2. |    e     259
809
>> 32.01%
>> >> 28.8%
>> >> >> 35.2%
>> >> >> >> 1.6% |
>> >> >> >>   3. |    c     121
345
>> 35.07%
>> >> 30.0%
>> >> >> 40.1%
>> >> >> >> 2.6% |
>> >> >> >>   4. |    d     262
726
>> 36.09%
>> >> 32.6%
>> >> >> 39.6%
>> >> >> >> 1.8% |
>> >> >> >>   5. |    b     192
480
>> 40.00%
>> >> 35.6%
>> >> >> 44.4%
>> >> >> >> 2.2% |
>> >> >> >>      |
>> >> >> >>   6. |    a     120
204
>> 58.82%
>> >> 52.1%
>> >> >> 65.6%
>> >> >> >> 3.4% |
>> >> >> >>   7. | mean     713
2153
>> 33.12%
>> >> 31.1%
>> >> >> 35.1%
>> >> >> >> 1.0% |
>> >> >> >>
>> >> >> >>
>> >> >>
>> >>
>>
+-------------------------------------------------------+
>> >> >> >>
>> >> >> >> Regards
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> --- On Sun, 18/1/09,
Martin
>> Weiss
>> >> >> >>
<[email protected]>
>> wrote:
>> >> >> >>
>> >> >> >> > From: Martin Weiss
>> >> >> <[email protected]>
>> >> >> >> > Subject: st: Re:
Monte
>> Carlo
>> >> Simulation,
>> >> >> help!
>> >> >> >> > To:
>> [email protected]
>> >> >> >> > Date: Sunday, 18
January,
>> 2009,
>> >> 11:49 AM
>> >> >> >> > A very warm
welcome to you
>> in the
>> >> Stata
>> >> >> community,
>> >> >> >> good to
>> >> >> >> > see you :-) Try
-help
>> simulate- for
>> >> a start!
>> >> >> >> >
>> >> >> >> > HTH
>> >> >> >> > Martin
>> >> >> >> >
_______________________
>> >> >> >> > ----- Original
Message
>> ----- From:
>> >> >> "STATA
>> >> >> >> Dndee"
>> >> >> >> >
>> <[email protected]>
>> >> >> >> > To:
>> >> <[email protected]>
>> >> >> >> > Sent: Sunday,
January 18,
>> 2009 12:46
>> >> PM
>> >> >> >> > Subject: st: Monte
Carlo
>> Simulation,
>> >> help!
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > > Hi
>> >> >> >> > > I want to
rank
>> institutions for
>> >> and
>> >> >> outcome given
>> >> >> >> in
>> >> >> >> > outcome% based on
Monte
>> Carlo
>> >> simulation and
>> >> >> produce a
>> >> >> >> table
>> >> >> >> > like table 2 in
>> >> >> >> >
>> >> >>
>> http://plus.maths.org/issue46/risk/index.html.
>> >> The
>> >> >> >> method
>> >> >> >> > is also described
by
>> Spiegelhalter
>> >> in BMJ,
>> >> >> 1998,
>> >> >> >> > 316(1701-1705).
>> >> >> >> > > I am a
beginner in
>> STATA. Could
>> >> anyone
>> >> >> help me in
>> >> >> >> > performing the
analysis in
>> STATA? I
>> >> need the
>> >> >> commands
>> >> >> >> and
>> >> >> >> > number of
iterations.
>> Number of
>> >> institutions
>> >> >> is more
>> >> >> >> than
>> >> >> >> > in the sample.
>> >> >> >> > >
>> >> >> >> > > Any help will
be
>> really
>> >> appreciated.
>> >> >> >> > > Kind regards
>> >> >> >> > >
>> >> >> >> > > Inst. cases
total
>> outcome%
>> >> >> >> > > f 71 273
26.01%
>> >> >> >> > > e 259 809
32.01%
>> >> >> >> > > c 121 345
35.07%
>> >> >> >> > > d 262 726
36.09%
>> >> >> >> > > mean 713 2153
33.12%
>> >> >> >> > > b 192 480
40.00%
>> >> >> >> > > a 120 204
58.82%
>> >> >> >> > >
>> >> >> >> > >
>> >> >> >> > >
>> >> >> >> > >
>> >> >> >> > > *
>> >> >> >> > > *   For
searches and
>> help try:
>> >> >> >> > > *
>> >> http://www.stata.com/help.cgi?search
>> >> >> >> > > *
>> >> >>
>> http://www.stata.com/support/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/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/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/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/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/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/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/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/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/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/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index