Dear all,
it took me a while to understand that $setobs is only applicable for
panel data once the time-dimension of the panel data set is set using
the setobs command with the '--panel-time' option.
However, this is only seems to work for annual and quarterly data
currently. See the following example which returns empty series for
frequencies 5 and 7:
<hansl>
clear
set verbose off
open grunfeld.gdt -q
# WORKS
setobs 1 2000 --panel-time
series obsdate = $obsdate
print obsdate -o --range=1:20
# WORKS
setobs 4 2000:1 --panel-time
series obsdate = $obsdate
print obsdate -o --range=1:20
# DOESN'T WORK
setobs 5 2000:1 --panel-time
series obsdate = $obsdate
print obsdate -o --range=1:20
# DOESN'T WORK
setobs 7 2000:1 --panel-time
series obsdate = $obsdate
print obsdate -o --range=1:20
</hansl>
The following function is a workaround:
<hansl>
function series get_obsdate_for_panel (const string init_date "YYYY-MM-DD",
const int frequency[7]
"Frequency of time-dimension",
const series crossdim
"Series defining the cross-sectional dim.")
/* Construct a panel series of $obsdate.
THIS FUNCTION IS OBSOLETE FOR ANNUAL AND QUARTERLY FREQUENCIES ONLY.
SIMPLY USE:
<hansl>
open grunfeld.gdt -q
setobs 1 1935 --panel-time
series obsdate = $obsdate
</hansl>
*/
if $datatype != 3
funcerr "This function only works for panel data."
endif
string str_frequency = sprintf("%d", frequency)
scalar T = $pd
scalar N = $tmax/T
smpl crossdim == min(crossdim) --restrict
setobs @str_frequency @init_date --time-series
matrix obsmat = $obsdate
smpl full
matrix mat = obsmat * ones(1, N) # T by N
series obsdate = vec(mat)
return obsdate
end function
</hansl>
Best,
Artur