Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: plot confidence intervals with time series
From
annoporci <[email protected]>
To
[email protected]
Subject
Re: st: plot confidence intervals with time series
Date
Sat, 22 Dec 2012 23:11:19 +0800
On Sat, 22 Dec 2012 20:03:37 +0800, Christopher Baum <[email protected]>
wrote:
Seems twoway lfitci is not too smart about format of the X-variable, so
you need to tell it:
graph twoway (lfitci $x1 $t, xlab(,format(%td))) (scatter $x1 $t)
Thanks Kit, that does the trick!
... though having to add ,xlab(,format(%td)) kills the simplicity of the
lfitci approach, so I think I'll stay with my second attempt, where I can
also control the significance level.
The data has high kurtosis so I'm thinking of using something other than
the t-distribution for the confidence intervals, does that make sense? I'm
thinking of replacing invttail with some other inverse tail, does it make
any sense?
Patrick.
my original question below:
Dear statalist,
A very simple question: I want to plot confidence intervals onto a time
series variable.
The problem I have is that in some cases the dates display as dates while
in other cases they display as numbers. I would like the dates to display
as dates.
I used rates.dta as an example, from the web data repository, even though
it doesn't produce interesting confidence intervals. Feel free to use
another dataset for illustration.
The following is my test code. Attempt 1 is what I understand to be the
natural approach: the graph has problems with the dates in this case.
Attempt 2 is my attempt to do things "by hand": the dates display as
expected in this case.
Follow-up question 1: is there a better way to plot confidence intervals
with a flexible value of the significance level, than my second attempt
below?
Follow-up question 2: can I plot the confidence intervals for the
logarithm of the variable "on the fly" or do I need to define a new
variable equal to the log of the level variable?
Follow-up question 3: does stata provide a confidence intervals command
under non-normal assumptions (e.g. Pareto)? or do I need to do it by hand
along the lines of my second attempt below?
I suspect my questions are FAQ so please do feel free to simply direct me
to some relevant url.
many thanks.
clear
cap log close
set more off
webuse rates.dta
global x1 dow
format date %td
tsset date
global t date
/* Construct a 95 percent confidence interval, attempt 1 */
graph twoway (lfitci $x1 $t) ///
(scatter $x1 $t) ///
, title("95% Confidence Interval (dates wrong!)")
graph export ci95_x1.ps,replace
/* Construct a 95 percent confidence interval, attempt 2 */
reg $x1 $t, robust
predict yhat, xb
predict shat, stdp
scalar define alpha = 0.9 /*significance level*/
gen crit = invttail(e(df_r),alpha/2)
gen upper = yhat + crit*shat
gen lower = yhat - crit*shat
graph twoway (scatter $x1 $t) ///
(line yhat $t) ///
(line lower $t) ///
(line upper date) ///
, title("Confidence Interval, significance level = `=alpha'")
graph export ci_x1.ps,replace
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/