[R] Analyzing Intervals between Data
jim holtman
jholtman at gmail.com
Sun Jul 27 07:14:54 CEST 2008
If I look at the data for one of the countries (Brazil), I see NAs in
the ranges. How is the following condition handled to determine the
"spell length"? Are values propogated forward"
426 1/12/00 Brazil (RS) 7.5 2000-01-12
425 3/18/00 Brazil (RS) 7.5 2000-03-18
424 3/31/00 Brazil (RS) 7.5 2000-03-31
423 5/6/00 Brazil (RS) 7.5 2000-05-06
422 2/5/01 Brazil (RS) NA 2001-02-05
421 4/1/01 Brazil (RS) NA 2001-04-01
420 5/3/01 Brazil (RS) 1.5 2001-05-03
419 11/4/01 Brazil (RS) 2.0 2001-11-04
418 12/2/01 Brazil (RS) 2.5 2001-12-02
417 12/9/01 Brazil (RS) 2.5 2001-12-09
416 12/31/01 Brazil (RS) 2.5 2001-12-31
415 2/26/02 Brazil (RS) 2.5 2002-02-26
414 4/25/02 Brazil (RS) 2.5 2002-04-25
413 4/28/02 Brazil (RS) 2.5 2002-04-28
412 6/10/02 Brazil (RS) 2.5 2002-06-10
411 6/30/02 Brazil (RS) 2.5 2002-06-30
410 3/31/03 Brazil (RS) 3.0 2003-03-31
409 5/2/03 Brazil (RS) 4.0 2003-05-02
408 7/10/03 Brazil (RS) 4.0 2003-07-10
407 11/30/03 Brazil (RS) 4.0 2003-11-30
406 12/31/03 Brazil (RS) 4.0 2003-12-31
405 4/30/04 Brazil (RS) 4.0 2004-04-30
404 6/30/04 Brazil (RS) 4.0 2004-06-30
403 9/7/04 Brazil (RS) 4.0 2004-09-07
402 10/31/04 Brazil (RS) NA 2004-10-31
401 11/28/04 Brazil (RS) NA 2004-11-28
400 12/31/04 Brazil (RS) NA 2004-12-31
399 1/2/05 Brazil (RS) NA 2005-01-02
398 1/3/05 Brazil (RS) 5.0 2005-01-03
397 1/31/05 Brazil (RS) 7.0 2005-01-31
396 4/30/05 Brazil (RS) 7.0 2005-04-30
395 7/31/05 Brazil (RS) 7.0 2005-07-31
394 8/5/05 Brazil (RS) 7.0 2005-08-05
393 1/11/06 Brazil (RS) 7.0 2006-01-11
392 5/2/06 Brazil (RS) 7.0 2006-05-02
391 11/30/06 Brazil (RS) 7.0 2006-11-30
390 3/31/07 Brazil (RS) 7.0 2007-03-31
389 6/30/07 Brazil (RS) 7.0 2007-06-30
On Sat, Jul 26, 2008 at 9:38 PM, Jia Ying Mei <jiamei at princeton.edu> wrote:
> 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.
>>>
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list