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.
Syntax and supported input types
DIFF(series)
DIFF(seriesList)| Input | Returns | Behavior |
|---|---|---|
| Single series | Data series | Subtracts each preceding observation from its current observation. |
| Data-series list | Data-series list | Applies 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 variable | Example levels | DIFF result | Interpretation |
|---|---|---|---|
| Unemployment rate (%) | 3.7 → 3.9 | 0.2 | Increase of 0.2 percentage points. |
| Payroll employment (thousands) | 150,000 → 150,100 | 100 | Increase of 100 thousand persons. |
| Price index | 100 → 110 | 10 | Increase of 10 index points. |
| Value in dollars | 50 → 45 | −5 | Decrease of 5 dollars. |
| Operation | Formula | Interpretation |
|---|---|---|
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 change | 100 × (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
- Check observation spacing. Consecutive stored observations may not represent consecutive calendar periods if the source has gaps. A change across a gap spans that gap.
- Expect a shorter series. The first input observation has no preceding value within the input sample. For a desired displayed start date, transform a sufficiently long history before clipping the result.
- Keep units clear. Levels measured in thousands yield differences in thousands. Rates measured in percent yield percentage-point differences.
- Match frequencies before comparing. Monthly differences and quarterly differences cover different intervals. Aggregating levels and then differencing can give a different result from aggregating the differences.
- Inspect revisions and exceptional periods. Data revisions, breaks, seasonal patterns and large shocks can affect differences as well as levels.
- Use differencing deliberately. It can reduce level trends, but it changes the economic question and does not automatically eliminate autocorrelation or establish stationarity.
LOGDIFF: proportional log changes · LAG: previous observations