{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ff456fa1",
   "metadata": {},
   "source": [
    "\n",
    "File: 02-dynamic.py\n",
    "\n",
    "\n",
    "Michel Bierlaire\n",
    "\n",
    "Thu Aug 07 2025, 17:43:26\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d4a3e70",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import biogeme.biogeme_logging as blog\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2553703c",
   "metadata": {},
   "source": [
    "The objective of this laboratory is to investigate the specification of choice models to capture dynamic behavior."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b34accb",
   "metadata": {},
   "source": [
    "As the estimation time may be long, we ask Biogeme to report the details of the iterations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "067e6433",
   "metadata": {},
   "outputs": [],
   "source": [
    "logger = blog.get_screen_logger(level=blog.INFO)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "800a5f45",
   "metadata": {},
   "source": [
    "We have generated synthetic data as follows. We postulate a true model\n",
    "for the data generation process. It is a mixture of logit models with\n",
    "two alternatives: `smoking` and `not smoking`. The utility for individual $n$ associated with `not smoking` in year $t$ is\n",
    "$$\n",
    "U_{0nt}= \\varepsilon_{0nt}\n",
    "$$\n",
    "and the utility associated with `smoking` is\n",
    "$$\n",
    "U_{1nt}= \\beta_{nt} y_{n,t-1} + \\beta^p_{nt} P_{t} + c_n + \\varepsilon_{1nt},\n",
    "$$\n",
    "where\n",
    "\n",
    "- $\\beta_{nt} = 10$,\n",
    "- $y_{n,t-1}=1$ if $n$ is smoking at time $t-1$, $0$ otherwise,\n",
    "- $\\beta^p_{nt} = -0.1$,\n",
    "- $P_t$ is the price of cigarettes at time $t$,\n",
    "- $c_n$ is an individual specific constant that captures the a priori, intrinsic attraction of each individual towards smoking. It is assumed to be normally distributed in the population, with zero mean and standard deviation 50: $N(0, 50^2)$, and constant over $t$.\n",
    "\n",
    "\n",
    "We have generated a sample of 1000 individuals, and we simulate their smoking behavior between the age of 16 until the age of 100.\n",
    "\n",
    "The date of birth of each individual is uniformly distributed between 2000 and 2020.\n",
    "The price of cigarettes in 2000 is supposed to be 10. The price of cigarettes in year $t$ is $$P_t = 10 \\cdot 1.02^{t-2000},$$\n",
    "which represents a price increase of 2% per year.\n",
    "\n",
    "The data file is `smoking.dat`.\n",
    "\n",
    "\n",
    "1. Estimate a simple static model.\n",
    "2. Estimate a dynamic Markov model.\n",
    "3. Estimate a static model accounting for serial correlation.\n",
    "4. Estimate a dynamic Markov model accounting for serial correlation.\n",
    "5. Compare and discuss the results."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44a1b081",
   "metadata": {},
   "source": [
    "**Tip:**<div class=\"alert alert-block alert-info\">It is advised to start working with a low number of draws, until\n",
    "the script is working well. Then, increase the number of draws to 10000, say. Then, execute the script overnight.\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c44dcf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "number_of_draws = 10"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
