Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
491 changes: 491 additions & 0 deletions pyfixest/Chapter01CorrAssocSimpsons.ipynb

Large diffs are not rendered by default.

File renamed without changes.
418 changes: 418 additions & 0 deletions pyfixest/Chapter04CREandNeyman.ipynb

Large diffs are not rendered by default.

847 changes: 847 additions & 0 deletions pyfixest/Chapter05StratandPostStrat.ipynb

Large diffs are not rendered by default.

393 changes: 393 additions & 0 deletions pyfixest/Chapter06RegadjRerand.ipynb

Large diffs are not rendered by default.

File renamed without changes.
136 changes: 136 additions & 0 deletions statsmodels/Chapter02PotentialOutcomes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chapter 2: Potential Outcomes"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pandas : 2.1.1\n",
"matplotlib : 3.8.0\n",
"scipy : 1.11.3\n",
"numpy : 1.23.5\n",
"matplotlib_inline: 0.1.6\n",
"\n"
]
}
],
"source": [
"import numpy as np\n",
"import scipy as sp\n",
"from IPython.core.interactiveshell import InteractiveShell\n",
"\n",
"InteractiveShell.ast_node_interactivity = \"all\"\n",
"\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 1\n",
"\n",
"%load_ext watermark\n",
"%watermark --iversions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"n = 500\n",
"Y0 = sp.stats.norm.rvs(size=n)\n",
"tau = -0.5 + Y0\n",
"Y1 = Y0 + tau"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Perfect doctor: treat if individual TE is positive"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.3555878913957384"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Z = tau >= 0\n",
"Y = Z * Y1 + (1 - Z) * Y0\n",
"np.mean(Y[Z == 1]) - np.mean(Y[Z == 0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Clueless doctor: flip coin"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.4046654673989749"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Z = sp.stats.bernoulli.rvs(p=0.5, size=n)\n",
"Y = Z * Y1 + (1 - Z) * Y0\n",
"np.mean(Y[Z == 1]) - np.mean(Y[Z == 0])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "econometrics",
"language": "python",
"name": "econometrics"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
351 changes: 351 additions & 0 deletions statsmodels/Chapter03CREandFRT.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions statsmodels/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
import pandas as pd
import graphviz as gr

def simulate(**kwargs):
values = {}
g = gr.Digraph()
for k,v in kwargs.items():
parents = v.__code__.co_varnames
inputs = {arg: values[arg] for arg in v.__code__.co_varnames}
values[k] = v(**inputs)
for p in parents:
g.edge(p, k)
return pd.DataFrame(values), g