Announcement

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

  • Calculating deltas

    Hello,

    I have a list of manufacturers by period and I am trying to calculate a delta like so:

    time_period chocolate_type manufacturer_count delta
    2011_Q1 White 3 --
    2011_Q2 White 4 1
    2011_Q3 White 4 0
    2011_Q4 White 3 -1
    2011_Q1 Dark 6 --
    2011_Q2 Dark 8 2
    2011_Q3 Dark 7 -1
    2011_Q4 Dark 10 3
    I have been trying to do
    HTML Code:
    bysort chocolate_type time_period: gen delta = manufacturer_count[_N] - manufacturer_count[_N -1]
    but keep getting syntax errors. Is there a way to do this in stata?

    Thanks!

  • #2
    Maroun:
    what about:
    Code:
    bysort chocolate_type ( time_period): g diff= manufacturer_count[_n+1]- manufacturer_count[n]
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo, thank you. This works great!
      Last edited by Maroun Mezher; 25 Nov 2025, 10:35.

      Comment

      Working...
      X