Statalist The Stata Listserver


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

st: re:locating the natural log of a number


From   "Victor M. Zammit" <vmz@vol.net.mt>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: re:locating the natural log of a number
Date   Sat, 31 Mar 2007 23:24:37 +0100

Dear Statalist,

I am trying to write a program to locate the natural log of any number
between 1 and 22026.

In this specific case I am trying the number 22000 but I am having trouble
with the error

sign "obs. out of range" as I try to get to the exact natural log of the
number in question.

Can any one give me any suggestions as to how to handle the problem.

The following is the best I could do :


qui {

drop _all

set obs 10000

gen a = .

gen exp = .

local n = 1

while `n'<= 9999 {

local e =.001

while `e'<= 10 {

replace exp = `e' in `n'

replace a = `n' in `n'

local e = `e'+.001

local n = `n'+1

}

}

gen nl = 20000

gen x = 2.718281828^exp

gen diff = x-nl

keep diff exp

save diff,replace

keep if diff<0

qui summ exp

local l = r(max)

}

di `l'

di 2.718281828^`l'

drop _all

use diff,clear

keep if diff>0

qui summ exp

local h = r(min)

di `h'

di 2.718281828^`h'



qui {

drop _all

set obs 10000

gen a = .

gen exp = .

local n = 1

while `n'<= 9999 {

local e = `l'

while `e'<= `h' {

replace exp = `e' in `n'

replace a = `n' in `n'

local e = `e'+.00001

local n = `n'+1

}

}

gen nl = 20000

gen x = 2.718281828^exp

gen diff = x-nl

keep diff exp

save diff,replace

keep if diff<0

qui summ exp

local l = r(max)

}

di `l'

di 2.718281828^`l'

drop _all

use diff,clear

keep if diff>0

qui summ exp

local h = r(min)

di `h'

di 2.718281828^`h'

*
*   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/



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