@during |

Indicator for whether an observation is between two dates

Syntax: @during(d)

d: string, alpha

Return: series

Returns a series containing indicators for whether each observation post-dates the first date d1 and precedes the end of the second date d2 of the range d.

• For dates in d that are of equal or lower frequency than the observation, the results are (0, 1) indicators of whether the observation matches or is in the interval.

• For dates in d that are of higher frequency than the observation, the results (0, n) reflect the fraction of the observation that is in the interval.

Note that the behavior of this function differs from
@before, in that it includes observations between the beginning and end of the final period that are not included when you apply @before to the final period.

Examples

Suppose that we have a quarterly workfile with data from 2020q1 to 2023q4 that we create with the command:

workfile q 2020 2023

The command

series during_y = @during("2021 2022")

uses a lower-frequency “yearly” date to creates the series DURING_Y containing the value 1 from 2022q1 through the 2022q4, and 0 elsewhere.

Using a “quarterly” date,

series during_q = @during("2021q3 2022q2")

creates the series DURING_Q containing the value 1 from 2021q3 through 2022q2 and 0 elsewhere.

The command using a higher frequency “monthly” date

series during_m = @during("2021m6 2022m5")

generates the series DURING_M containing a fractional value for 2021q2, 1 from 2021q3 through 2022q1, a fractional value for 2022q2, and the 0 elsewhere.

For the fractional 2021q2 value, there are 60 days in 2021-Apr and 2021-May that precede the starting “2021m6” date. There are 91 days in the full quarter, so the fractional included value for 2021q2 is (91-60)/91 = 0.32967.

For the fractional 2022q2 value, there are 61 days in 2021-April and 2021-May that precede the end of the “2022m5” date. There are 91 days in the full quarter, so the fractional before value for 2022q2 is 61/91 = 0.6793.

Cross-references