Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating cosine and sine

    Hello. I am very new for STATA. So, please forgive me if my question is too basic. I am trying to run negative binomial regression with my monthly data (Jan 2018 -Dec 2022) to check if injury depends on sex and age-group (Here I simplified my dataset by removing some other variables). Trend of injury seems to be cyclical in graph. I have attached my data. So, i wanted to include sine and cosine terms into the model. I used the following code to create sine and cosine terms.

    gen time = _n
    gen period = 12
    gen sine_term = sin(2 * _pi * time / period)
    gen cosine_term = cos(2 * _pi * time / period)

    After that I run nbreg to calculate incidence rate ratio.

    nbreg Injury ib0.Age_group ib1.Sex sine_term cosine_term, dispersion(mean) exposure(Pop1) irr

    I had following output:
    ----------------------------------------------------------------------------
    Injury | IRR Std. err. z P>|z| [95% conf. interval]
    -------------+----------------------------------------------------------------
    1.Age_group | 1.229485 .0772512 3.29 0.001 1.087027 1.390612
    2.Sex | .7773731 .0371441 -5.27 0.000 .707877 .8536921
    sine_term | 1.001287 .0337199 0.04 0.970 .937331 1.069607
    cosine_term | 1.077418 .0365459 2.20 0.028 1.008119 1.151482
    _cons | .0004817 .0000297 -124.04 0.000 .0004269 .0005435
    ln(Pop1) | 1 (exposure)
    -------------+----------------------------------------------------------------
    /lnalpha | -.5951414 .0483545 -.6899145 -.5003684
    -------------+----------------------------------------------------------------
    alpha | .5514846 .0266668 .5016189 .6063073

    Sine term is insignificant here (But if I add another variables both cosine and sine became insignificant).

    My question is:

    Is it possible that sine and cosine to be insignificant when there is clear cyclical pattern?
    Is my code correct (for sine and cosine)?



    Thank you very much.

    Attached Files

  • #2
    There are various examples you may find useful in this article by Nick Cox: https://journals.sagepub.com/doi/pdf...867X0600600408
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks to Maarten Buis for the mention. Among other details, my paper repeats and explains standard advice always to use sine and cosine terms in pairs, regardless of P-values or other inferential results. Here the stronger cosine term implies a peak near January and a trough near July, which could well make perfect sense. I have not downloaded the data to check.

      Please see FAQ Advice #12 for our requests on attachments, which include asking that you don't post spreadsheet files.

      With such data, I typically use 2 pi (month - 0.5) / 12 as a perhaps pointless refinement to centre each month value on its middle.

      Whether monthly data should be scaled by the number of days in each month is also up for discussion.

      The more a phenomenon is linked to people's behaviour, the less sine and cosine terms are good for modelling seasonality. Economists in particular usually start with the idea that holidays or vacations of whatever kind make indicator (dummy) variables for each month a good idea, but that approach uses up quite a few degrees of freedom.
      Last edited by Nick Cox; 05 Dec 2023, 03:27.

      Comment

      Working...
      X