Skip to content

Instantly share code, notes, and snippets.

@NaimKabir
Last active October 21, 2019 03:11
Show Gist options
  • Save NaimKabir/720b684ad8917174eb6b1bd5742a2303 to your computer and use it in GitHub Desktop.
Save NaimKabir/720b684ad8917174eb6b1bd5742a2303 to your computer and use it in GitHub Desktop.
Showing how to do a quick intention-to-treat given rct results
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Intent-to-treat average treatment effect\n",
"\n",
"All we need to do is sum up all 'good' from the Treatment column, and subtract by all 'good' from the Control column.\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ATE: 0.4512\n"
]
}
],
"source": [
"p_good_treated = df[\n",
" df.assignment == \"treatment\"\n",
"].good_outcome.mean()\n",
"\n",
"p_good_control = df[\n",
" df.assignment == \"control\"\n",
"].good_outcome.mean()\n",
"\n",
"itt_ate = p_good_treated - p_good_control\n",
"\n",
"# display\n",
"print(\"ATE: %6.4f\" % itt_ate)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment