[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Stata's "Simulate" command and Stata v.8.1 |

Date |
Tue, 19 Aug 2003 20:43:26 +0100 |

Miller.DavidJ@epamail.epa.gov > > I am fairly new to Stata programming but would like to perform a > simulation whereby I create a dataset containing means and > variances of > 1000-observation samples from a log-normal distribution with a given > mean and standard deviation. I would like to output the > 1000 generated > mean and standard deviations pairs (or doublets) and plot > these as (x,y) > coordinates . Eventually, I would also like the output to > contain the > skewness and kurtosis and understand that, to do this, I > would need to > use the "summarize, detail" command and I could do this using > incorporating r(skewness) and r(kurtosis) as output > requests into the > program. > > As a first step in this process, I thought I would try out > an example in > Stata's on-line help function and see if it worked. I typed "help > simulate" into Stata and copied a sample program from there > into Stata. > When I did this, however, Stata told me that there was an > "error when > command executed on original dataset under version 8.1 > control r(199);" > As this was a sample command taken directly from the Stata > on-line help > files, I was puzzled. I thought that it might help to add > in "version > 8.0" into the program as line 1 (so that it would > understand that it was > supposed to work under the the 8.0 version of Stata), but > this didn't > work either and Stata came back with the same error. > > Does anyone know what needs to be done to modify programs if the 8.1 > version of Stata will now longer accept them? Or if I am doing > something wrong? I am using Stata 8.1 born 01 July 2003. I have > excerpted below my sample program which was copied directly from a > sample program provided under Stata's on-line help function > as well as > Stata's response about v.8.1 control. > > . about > > Intercooled Stata 8.1 for Windows > Born 01 Jul 2003 > Copyright (C) 1985-2003 > > Total physical memory: 259992 KB > Available physical memory: 4224 KB > > > program define lnsim, rclass > 1. syntax [, obs(integer 1) mu(real 0) sigma(real 1)] > 2. drop _all > 3. set obs `obs' > 4. temvar z > 5. gen `z'=exp(`mu' + `sigma' * invnorm(uniform())) > 6. summarize `z' > 7. return scalar mean=r(mean) > 8. return scalar Var = r(Var) > 9. end > > . simulate "lnsim, obs(100)" mean=r(mean) var=r(Var), reps(10000) > > command -> lnsim , obs(100) > error when command executed on original dataset under version 8.1 > control > r(199); > > . simulate "lnsim, obs(50) mu(-3) sigma(7)" mean=r(mean) var=r(Var), > reps(10000) > > command -> lnsim , obs(50) mu(-3) sigma(7) > error when command executed on original dataset under version 8.1 > control > r(199); I think at least some of this revolves around a typo, "temvar" for "tempvar". For want of a "p", the program fell over. I wouldn't use -simulate- here. Why? Because you could do all it in one with m blocks of n. This can also be extended with -egen, skew()- and -egen, kurt()-. Not the most efficient way to do, but relatively straightforward. program lnsim2 version 8 args m n mu sigma garbage if "`garbage'" != "" | "`sigma'" == "" error 198 clear set obs `= `m' * `n'' tempvar z group mean sd tag gen `z'=exp(`mu' + `sigma' * invnorm(uniform())) gen `group' = mod(_n,`m') egen `mean' = mean(`z'), by(`group') egen `sd' = sd(`z'), by(`group') bysort `group' : gen byte `tag' = _n == 1 scatter `sd' `mean' if `tag', ytitle(sd) xtitle(mean) end lnsim2 1000 1000 0 1 Nick n.j.cox@durham.ac.uk * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Stata's "Simulate" command and Stata v.8.1***From:*Miller.DavidJ@epamail.epa.gov

- Prev by Date:
**st: RE: Location of the knots when estimating a spline model** - Next by Date:
**Re: st: Copy and paste** - Previous by thread:
**st: Stata's "Simulate" command and Stata v.8.1** - Next by thread:
**st: Location of the knots when estimating a spline model** - Index(es):

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