Module 3 · Data, Variables, Samples, and Measurement Lesson 24 of 120

Cross-Sectional, Time-Series, Panel, and Event Data

Customer histories and payment events have different grains.

2:43 clip1:16:18–1:19:01 in the full courseWatch on YouTube

Transcript

21 sentences · select one to jump there

Check your understanding

Is an absent customer-month record necessarily a zero balance?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

024-cross-sectional-time-series-panel-and-event-data.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 024 of 120
 * Cross-Sectional, Time-Series, Panel, and Event Data
 * Module 03: Data, Variables, Samples, and Measurement
 *
 * Scenario: Customer histories and payment events have different grains
 * Rule:     snapshot · sequence · panel · event stream
 *
 * Try it:   Is an absent customer-month record necessarily a zero balance?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/cross-sectional-time-series-panel-and-event-data/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson024() {
  const rows = [
   {id: "C1", month: "Jan", balance: 10},
   {id: "C1", month: "Feb", balance: 12},
   {id: "C2", month: "Jan", balance: 8}
  ];
  const key = (r: typeof rows[number]) => `${r.id}|${r.month}`;
  const result = new Set(rows.map(key)).size;
  return result;
}

export const checkedResult = 3;

// Run this file directly: npx tsx lessons/03-data-variables-samples-and-measurement/024-cross-sectional-time-series-panel-and-event-data.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson024(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

3

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

snapshot · sequence · panel · event stream