Hi!

It worked very well. Just for the record, I used the consecutive count inside a loop:

<hansl>
loop i=1 .. nelem(stocks)
series streak\$i = ok(stock\$i[1])
streak\$i = ok(stock\$i) ? streak\$i(-1) + 1 : 0
scalar nobservations = max(streak\$i)
streak += streak\$i
if nobservations < @min_obs_shares # min number of observations
stocks_ins_obs += stock\$i
endif
endloop
</hansl>

Basically I have a list of stocks (stock1, stock2, stock3), named "stock". I loop through that list to check all stocks that have a number of consecutive observations that is less than "min_obs_share". If true, I send the stock to a new list "stocks_ins_obs".

That's it

Thanks!
F.R.Costa
--
https://tutanota.com

Apr 28, 2020, 15:59 by cottrell@wfu.edu:
On Tue, 28 Apr 2020, Riccardo (Jack) Lucchetti wrote:
On Tue, 28 Apr 2020, F.R.Costa wrote:
I guys,hope you're all well,

I have a very quick question. I am working with stock market data. Let's say I have price observations for stock X. I want to exclude stock X from my data if it doesn't have at least 24 consecutive observations. Is there any simple command able to retrieve a consecutive count of observations. \$nobs would give a total count, but is there a way to take account of this?

You may find this example useful:

<hansl>
set verbose off
set seed 123
nulldata 60
setobs 5 2020-01-01

# construct an artificially "gappy" series
x = uniform() < 0.8 ? normal() : NA

# now compute the streaks
series streak = ok(x[1]) # initialise
series streak = ok(x) ? streak(-1) + 1 : 0 # compute the actual streaks

printf "longest streak = %d\n", max(streak)

print x streak -o
</hansl>

Filipe, Jack beat me to it, with a more concise and elegant version than I was writing, but just in case it's helpful here's another approach.

<hansl>
set verbose off
nulldata 700
setobs 12 1960:01
series x = normal()
x = abs(x) > 2.4 ? NA : x
summary x --simple

maxconsec = 0
loop i = 1..\$nobs --quiet
consec = 0
loop j = i..\$nobs --quiet
if ok(x[j])
consec++
else
break
endif
endloop
if consec > maxconsec
maxconsec = consec
endif
endloop

printf "x has a max of %d consecutive observations\n", maxconsec
</hansl>

Allin
_______________________________________________
Gretl-users mailing list -- gretl-users@gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave@gretlml.univpm.it
Website: https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/