[R] Analyzing Intervals between Data

Jia Ying Mei jiamei at Princeton.EDU
Sun Jul 27 03:38:10 CEST 2008


Hi Jim,

I did define it, although I guess I wasn't clear. The spell length is 
essentially the interval of time between price changes. So in the data, 
say a price starts at 3, and then 150 days later, the price changes to 
4. The "spell length" is 150, the interval of time between the price 
change. I am looking, country by country, for the mean and median of 
these lengths of times themselves.

So I am not actually doing anything with the data within the intervals 
(because the data doesn't change), but finding information about the 
intervals themselves. I hope that clears it up? Thanks for dealing with 
my questions.

Jia Ying Mei

jim holtman wrote:
> You need to provide a definition of what the "spell length" is since I
> am not an economist.  Given that you have a list of prices, how do you
> determine the spell length and then what do you do with the data in
> each interval?  This is what you would have to clarify, at from my
> point of view, so that we could understand what you want to do with
> the data.  I assume that if you have the data, then there was some
> manual (automated function in some other language) that did a
> transformation on the data.  Maybe someone else with an economic
> background can point you in the right direction.
>
> On Sat, Jul 26, 2008 at 8:09 PM, Jia Ying Mei <jiamei at princeton.edu> wrote:
>   
>> 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.
>>



More information about the R-help mailing list