| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: re:locating the natural log of a number
Victor,
I don't understand what are you doing with your code.
But I think that you want
set obs 22026
gen n = _n
gen double nl = log(_n)
Rodrigo.
----- Original Message -----
From: "Victor M. Zammit" <[email protected]>
To: <[email protected]>
Sent: Saturday, March 31, 2007 6:24 PM
Subject: st: re:locating the natural log of a number
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/
*
* 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/