[R] Analyzing Intervals between Data
Jia Ying Mei
jiamei at Princeton.EDU
Sun Jul 27 02:09:20 CEST 2008
Hi,
The truth is, I really don't have any idea what I want to do code-wise,
because I'm not familiar with doing this kind of stuff in R.
What I need is the mean and median for the spell length of a price (i.e.
prices change over time, but what is the mean and median of the length
of each interval between changes?), see the attached economist pdf file
for an idea of what data I am trying to get.
So, I have these two text files that I can merge and fill in the missing
values like so:
> fmt<-"%m/%d/%y"
> dd<-read.csv("Desktop/R/CDSdate.txt")
> dd$Date<-as.Date(dd$Date, fmt)
>library(zoo)
> data<-read.zoo("Desktop/R/Countrydata.txt", head=T, format=fmt,
sep="\t")
>newdata<-merge(data, zoo(,dd$Date)
>Finaldata<-na.locf(newdata, fromLast=TRUE)
I need some way after this to find the mean and median of the intervals
themselves between each price change by country. Looking at the
breakdown below, that seems to be mean and median of prices within
certain intervals (not sure though), but that is not what I need.
Attached is the rough code in Stata for those who know Stata and can
convert into R, but for a different set of data that is formatted the
same way. I feel like I've come back to square 1, but ANY help would be
appreciated, thanks! If not clear, I can definitely clarify points.
Jia Ying Mei
PS. I want to do this in R because I know it will be less complicated in
R and because I don't own Stata.
jim holtman wrote:
> The original example that you sent was in the long format:
>
>
>> brkdn(intervals~country,jymint.df,num.desc=c("mean","median"))
>>
>
> Breakdown of intervals by country
> Level mean median
> au 0.01 0
> br -0.07 1
> cn -0.32 2
> in 0.31 -1
> us -0.4 7
>
>> head(jymint.df,20)
>>
> country intervals
> au1 au 65
> au2 au -54
> au3 au 27
> au4 au -35
> au5 au 23
> au6 au 29
> au7 au -4
> au8 au -49
> au9 au 42
> au10 au -48
> au11 au 51
> au12 au 27
> au13 au -11
> au14 au 0
> au15 au -37
> au16 au 33
> au17 au -32
> au18 au -12
>
> It was not clear exactly how you wanted to come up with the intervals,
> but if you want to do them by country, then the logical place to start
> is the long format. Can you provide and example of exactly what you
> would be doing with the data to get the intervals. It is hard to tell
> from a "word" description what type of data transformations you would
> like to do. Take a small subset of the data and show what the
> before/after objects might look like.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theeconomist07122008.pdf
Type: application/pdf
Size: 29473 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080726/3d2ae63c/attachment.pdf>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CDSdate.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080726/3d2ae63c/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Countrydata.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080726/3d2ae63c/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Part 1.7
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080726/3d2ae63c/attachment.pl>
More information about the R-help
mailing list