Dear Stata users,
The command -growthi- was introduced by Sean Becketti in May 1994 (STB-19: sts7.2). It was designed to display growth rate immediately. Now when I run it in Stata 16, something wrong happens.
I set trace on, and find that the problem lies in the following line: local lag=cond("`annual'"="",1,`lag')
How do I modify it to run under Stata 16? Thank you very much.
The command -growthi- was introduced by Sean Becketti in May 1994 (STB-19: sts7.2). It was designed to display growth rate immediately. Now when I run it in Stata 16, something wrong happens.
Code:
. growthi 15 17
type mismatch
r(109);
How do I modify it to run under Stata 16? Thank you very much.
Code:
*! growthi -- immediate form of growth command
*! version 1.0.0 Sean Becketti May 1994
*
* "growthi old_exp new_exp, options" calculates growth rate going from
* old_exp to new_exp
*
program define growthi
version 3.1
/*
Store the expressions, then see if we can evaluate them.
Watch out for the comma.
*/
global S_1 = .
local oldexp "`1'"
mac shift
tempname old
cap scalar `old' = `oldexp'
local rc = _rc
if `rc' {
di in ye "`oldexp' " in re "... is not a legal expression"
exit `rc'
}
local newexp "`1'"
mac shift
local rmndr "`*'"
local i = index("`newexp'",",")
if `i' { /* comma is in 2nd expression */
local comma = substr("`newexp'",`i',.)
local i = `i' - 1
local newexp = substr("`newexp'",1,`i')
local rmndr "`comma' `rmndr'"
}
tempname new
cap scalar `new' = `newexp'
local rc = _rc
if `rc' {
di in ye "`newexp' " in re "... is not a legal expression"
exit `rc'
}
local options "noAnnual LAg(int 1) Log Percent PERIod(str)"
parse "`rmndr'"
_ts_peri `period' /* obtain # of periods per "year" */
local period=cond("`annual'"!="",1,$S_1)
local lag=cond("`annual'"="",1,`lag')
local f100=cond("`percent'"!="",100,1)
local pwr=`period'/`lag'
tempname growth
quietly {
if ("`log'"!="") {
scalar `growth'=`f100'*`pwr'*(ln(`new')-ln(`old'))
}
else {
scalar `growth' = `f100'*((`new'/`old')^`pwr'-1)
}
}
global S_1 = `growth'
global S_2 = `lag'
global S_3 = `old'
global S_4 = `new'
global S_5
di in ye = `growth'
end
Comment