Home · Command reference

RainbowStats™ · Command reference

DIFF — Absolute Changes

Measure how much a series rises or falls between consecutive observations.

DIFF subtracts the previous observation from the current one. It accepts a single time series or a data-series list, applying the transformation separately to each member. The result measures an absolute change in the original variable’s units.

Quick start: unemployment-rate changes

change = DIFF(SERIES_SINCE(UNRATE,20010101))
LINE_CHART(SET_UNITS(SET_NAME(change,"Monthly unemployment-rate change"),"Percentage points"))

Run this example in RainbowStats

This charts monthly changes in the unemployment rate. An increase from 3.7% to 3.9% produces 0.2, meaning a rise of 0.2 percentage points.

DIFF is an absolute change. For a percentage-valued rate, interpret the difference in percentage points. For payroll employment measured in thousands of persons, interpret it in thousands of persons. No automatic percentage-change calculation is performed.

Syntax and supported input types

DIFF(series)
DIFF(seriesList)
InputReturnsBehavior
Single seriesData seriesSubtracts each preceding observation from its current observation.
Data-series listData-series listApplies the same one-period difference separately to every series in the list.

The supplied dispatcher supports the one-argument command. It has no two-argument DIFF(series,n) implementation. For an explicit longer interval, use subtraction with LAG.

Calculation and units

DIFF(x)[t] = x[t] − x[t−1]
Original variableExample levelsDIFF resultInterpretation
Unemployment rate (%)3.7 → 3.90.2Increase of 0.2 percentage points.
Payroll employment (thousands)150,000 → 150,100100Increase of 100 thousand persons.
Price index100 → 11010Increase of 10 index points.
Value in dollars50 → 45−5Decrease of 5 dollars.
OperationFormulaInterpretation
DIFF(x)x[t] − x[t−1]Absolute change in the original variable’s units.
LOGDIFF(x)ln(x[t] / x[t−1])Fractional log change; multiply by 100 for a log change expressed in percent.
Simple percentage change100 × (x[t] / x[t−1] − 1)Ordinary percentage change; close to 100 × LOGDIFF only for small changes.

The tested unemployment-rate transformation retains the source units label “Percent.” The arithmetic result must be read as a percentage-point change; use SET_UNITS to make that distinction clear in charts.

Differencing a monthly series produces changes between consecutive monthly observations. It does not change the frequency or annualize the result.

Examples: payrolls, lists and longer intervals

Monthly payroll changes

payroll_change = DIFF(SERIES_SINCE(PAYEMS,20010101))
LINE_CHART(SET_NAME(payroll_change,"Monthly payroll employment change"))

Because PAYEMS is measured in thousands of persons, a difference of 100 means an increase of 100,000 persons.

Transform a list for regression

levels = LIST(SERIES_SINCE(PAYEMS,20010101),SERIES_SINCE(INDPRO,20010101))
changes = DIFF(levels)
r = REGRESSION(changes)
EXTRACT(r,"slideshow")

This relates payroll changes to industrial-production index changes. Each transformed series retains its own economic units. The regression slope therefore measures thousands of persons per production-index point; it is not an elasticity.

Difference over twelve monthly observations

x = SERIES_SINCE(UNRATE,20000101)
annual_change = x-LAG(x,12)
LINE_CHART(SET_UNITS(SET_NAME(annual_change,"Twelve-month unemployment-rate change"),"Percentage points"))

This explicitly calculates x[t] − x[t−12]. Use this form instead of DIFF(x,12).

Calculate a second difference

x = SERIES_SINCE(PAYEMS,20010101)
second_difference = DIFF(DIFF(x))
LINE_CHART(SET_NAME(second_difference,"Change in monthly payroll gains"))

The second difference is x[t] − 2*x[t−1] + x[t−2]. It measures the change in the first difference and is distinct from x-LAG(x,2), which is the cumulative change over two observation intervals.

Calculate a simple percentage change instead

x = SERIES_SINCE(INDPRO,20010101)
percent_change = 100*(x/LAG(x,1)-1)
LINE_CHART(SET_UNITS(SET_NAME(percent_change,"Monthly industrial production change"),"Percent change"))

The ratio form requires a suitable nonzero comparison value. Use LOGDIFF when fractional logarithmic changes of positive levels are the desired measure.

Differences through EXTRACT

x = SERIES_SINCE(UNRATE,20010101)
change = EXTRACT(x,"diff")
LINE_CHART(change)

A single SeriesOperator supports the "diff" extract and returns a data series. The result can be charted or passed to other series operations.

DataListOperator supports the direct DIFF(list) command but does not implement the "diff" extract. Use the direct command for lists.

Working with the data

LOGDIFF: proportional log changes · LAG: previous observations