Search code examples
datetimetimetime-seriesstata

How can I set a time variable that takes 2-months (bimonthly data)?


I can't find a way to define a time variable in Stata that takes two months. I found in other forums the way to define intervals of 3 months (quarters) or to define it as a semester, but that is not what I'm looking for.

I have a data set like this

year month observation
2000   1        40
2000   2        10
2000   3        50
2000   4        10

I created a variable bi_month as

year month bi_month observation
2000   1       1        40
2000   2       1        10
2000   3       2        50
2000   4       2        10

but here I'm not able to use the following code nor the tsset command (because it doesn't have a command of definition bimonthly data)

 gen mdate = ym(year, bi_month)
 format mdate %tm

because Stata reads bi_month as indicating months from 1 to 12.


Solution

  • Bi-monthly (or bimonthly) doesn't seem to me especially transparent as a term. I recommend twice-monthly and two-monthly for two interpretations.

    The main issue here is, it seems, wanting to work with an aggregation of monthly data to two-monthly data, specifically intervals Jan-Feb, ..., Nov-Dec. To that end I suggest representing two-month periods by the first month of each.

    clear 
    input year month whatever 
    2000   1        40
    2000   2        10
    2000   3        50
    2000   4        10
    end 
    
    gen mdate = ym(year, month) 
    
    gen m2date = 2 * floor(mdate/2) 
    
    format m*date %tm 
    
    list
    
    
         +-------------------------------------------+
         | year   month   whatever    mdate   m2date |
         |-------------------------------------------|
      1. | 2000       1         40   2000m1   2000m1 |
      2. | 2000       2         10   2000m2   2000m1 |
      3. | 2000       3         50   2000m3   2000m3 |
      4. | 2000       4         10   2000m4   2000m3 |
         +-------------------------------------------+
    

    Now such data can't be tsset or xtset using the new two-monthly date because each such date doesn't occur uniquely in the dataset.

    But supposing that you reduce your dataset so that each two-monthly date occurs just once (or, maximally, once per panel). Now tsset or xtset is within reach, and the needed twist is just to set delta(2).

        collapse whatever, by(year m2date) 
    
        tsset m2date, delta(2) 
    
        list 
    
        +--------------------------+
         | year   m2date   whatever |
         |--------------------------|
      1. | 2000   2000m1         25 |
      2. | 2000   2000m3         30 |
         +--------------------------+
    

    Representing each two-month period by the second month of each is equally systematic. Just add 1 to the recipe for m2date above.

    Note: Strictly xtset requires only a panel identifier and doesn't insist on times occurring at most once for each panel. I am not sure that is widely useful, but it's another story.