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

From |
Eric Booth <ebooth@ppri.tamu.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: argument with digits after decimal point? |

Date |
Thu, 31 Dec 2009 19:55:56 -0600 |

<> Dirk: A couple of issues here. #1 Realize that there is already a program -test- in Stata, so you need to either change the name or -drop program- test before running your code. #2 When you ask Stata to capture the real number in ci(99.9), it captures the real number "99.90000000000001", not "99.9", which is what the -set level- command doesn't like, so it give you the error. See the results of running your program with -set trace on- below: ----------------------------------------------------------------------- begin test --- - syntax [, ci(real 95)] - set level `ci' = set level 99.90000000000001 level() can have at most two digits after the decimal point ------------------------------------------------------------------------- end test --- So, you need to round `ci' before passing it to the -set level- command. I'm not a Stata programmer, so I don't know if there are better ways of doing this in a program, but here's one way that worked for me (NOTE: I changed your program to "test22" to avoid issues I mentioned in #1 above): *************** clear sysuse auto * -------------------------- cap program drop test22 program define test22 syntax [, ci(real 95)] di "before rounding: " "`ci'" local ci2 : display round(`ci', .01) local ci = "`ci2'" di "after rounding: " "`ci'" set level `ci' end * -------------------------- * -------------------------- test22, ci(99.99) * -------------------------- *************** #3 Finally, the -syntax- help file indicates that there is already a pre-built option in there for grabbing the confidence level. There might be other reasons that you want to capture it in the `ci' macro, but if not, you might try substituting in the -ci(cilevel)- option: **************** clear sysuse auto * -------------------------- cap program drop test22 program define test22 syntax [, ci(cilevel)] set level `ci' di "`ci'" end * -------------------------- * -------------------------- test22, ci(99.9) * -------------------------- ****************** ~ Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Dec 31, 2009, at 6:46 PM, Dirk Enzmann wrote: > Why does the following program not work as intended? > > * -------------------------- > program define test > syntax [, ci(real 95)] > set level `ci' > end > * -------------------------- > > It is an example of a program that allows the optional argument "ci" to specify the confidence level (the default should be 95). It works as intended as long as I don't specify "ci" with digits after the decimal point. But if I do, for example > > * -------------------------- > test, ci(99.9) > * -------------------------- > > I receive the error message "level() can have at most two digits after the decimal point". What am I doing wrong, i.e. how can I avoid this problem? > > *************************** > Dirk Enzmann > dirk.enzmann@uni-hamburg.de > * > * 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/

**References**:**st: argument with digits after decimal point?***From:*Dirk Enzmann <dirk.enzmann@uni-hamburg.de>

- Prev by Date:
**st: argument with digits after decimal point?** - Previous by thread:
**st: argument with digits after decimal point?** - Index(es):

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