Page 1 of 1

Continuous sample selection for estimation procedure

Posted: Wed Nov 20, 2013 3:40 am
by chernayj
Hi

I am trying to code a programme to run a recursive estimation procedure for a host of series. Some of the series have breaks and I need to select a continuous sample for each estimation iteration.

I have tried using the code, for say a generic series named x:

smpl if x <> na

However this selects the starting date for the sample as from the first non-missing observation, irrespective of non-missing observations that may be present between the first and last non-missing obs.

Imagine that the x series looks something like:

Date x
2007m12 na
2008m1 2
2008m2 5
2008m3 na
2008m4 7
2008m5 9
2008m6 10

Using the command:
smpl if x <> na
selects the sample range 2008m1 2008m6, where the continuous sample range for the series is in fact 2008m4 2008m6.

Please help????

Re: Continuous sample selection for estimation procedure

Posted: Wed Nov 20, 2013 7:55 am
by chernayj
Figured out the solution for anyone who is interested, subroutine code below:

Code: Select all

subroutine estsmpl(series x) 'Capture observation number for last non-missing obs of series smpl @all !lastnm = @ilast(x) !nobs = @obsrange 'Loop to capture the longest continuous sample range for the series for !i = 1 to !nobs step 1 %temps = @otod(!lastnm - !i) %templ = @otod(!lastnm) smpl {%temps} {%templ} scalar nnas = @nas(x) if nnas = 0 then next else %first = @otod(!lastnm - !i + 1) %last = @otod(!lastnm) sample c_smpl {%first} {%last} smpl c_smpl string = exitloop endif endsub