Statalist


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

st: Re: statalist-digest V4 #3656


From   Dirk Enzmann <[email protected]>
To   [email protected]
Subject   st: Re: statalist-digest V4 #3656
Date   Fri, 01 Jan 2010 12:38:24 +0100

Eric,

thanks a lot, your reply was very helpful!

What I learned:
1) to use - local xx : display - to format (round) the value,
2) to use "cilevel" for grabbing the confidence level,

and not to call a foo program - test -.

A happy New Year to you and the Statalist!

***************************
Dirk Enzmann
[email protected]

Date: Fri, 1 Jan 2010 00:49:55 -0600
From: Eric Booth <[email protected]>
Subject: Re: st: argument with digits after decimal point?

<>

Apparently, you don't need to create the macro "ci2", just replace "ci" with a rounded version of its self to shorten the code I gave earlier,  so:

***************
clear
sysuse auto

* --------------------------
cap program drop test22
program define test22
 syntax [, ci(real 95)]
di  "before rounding: "  "`ci'"
local ci : display round(`ci', .01)
di  "after rounding: "  "`ci'"
 set level `ci'
end
* --------------------------
* --------------------------
test22, ci(99.9)
* --------------------------
***************

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754


On Dec 31, 2009, at 7:55 PM, Eric Booth wrote:


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
[email protected]
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?

--
*************************************************
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany

phone: +49-(0)40-42838.7498 (office)
       +49-(0)40-42838.4591 (Billon)
fax:   +49-(0)40-42838.2344
email: [email protected]
www: http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
*************************************************
*
*   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