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>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------