Page 1 of 1
Observation IDs within a sample
Posted: Mon May 09, 2011 8:56 am
by jthodge
Is there a way to create a series for an unstructured workfile that shows the relative observation IDs within a sample?
The @OBSNUM and @OBSID functions give the absolute observation IDs relative to the entire workfile range.
I'd like to know the observation IDs relative to the first observation within the sample.
Re: Observation IDs within a sample
Posted: Mon May 09, 2011 9:01 am
by EViews Gareth
I cannot think of an easy way to get it, no :(.
Re: Observation IDs within a sample
Posted: Mon May 09, 2011 9:10 am
by startz
Something like
Code: Select all
series foo = @obsid - @min(@obsid)
Re: Observation IDs within a sample
Posted: Mon May 09, 2011 9:14 am
by EViews Gareth
That assumes the observations in the sample are consecutive.
Re: Observation IDs within a sample
Posted: Mon May 09, 2011 9:41 am
by jthodge
Startz's idea should work for me since the observations within my sample are consecutive.
However, to clarify, I think you first need to set the sample in the workfile, of course, and you need to add 1 so that the first obs id within the sample is 1 and not 0:
Code: Select all
smpl ...
series foo = @obsid - @min(@obsid) + 1
I didn't think about what would happen with non-consecutive observations in the sample. That would definitely add some complexity.
Re: Observation IDs within a sample
Posted: Mon May 09, 2011 9:44 am
by EViews Gareth
This works in the more general, non-consecutive case:
Code: Select all
series ser = 1
series id = @cumsum(ser)
Since ser will only be equal to 1 for observations in the current sample, the cumulation works.