{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e13951bc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loaded client.js from C:\\Users\\jjsan\\GitHub\\jupyter-notebook-mcp\\src\\client.js\n", "WebSocket server started on ws://localhost:8765\n" ] }, { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "

Jupyter MCP Integration Setup Complete

\n", "

WebSocket server is running on port 8765

\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Jupyter client connected\n", "External client connected (likely MCP server)\n" ] } ], "source": [ "import sys\n", "sys.path.append('C:/Users/jjsan/GitHub/jupyter-notebook-mcp/src') # absolut or relative path to src folder\n", "from jupyter_ws_server import setup_jupyter_mcp_integration\n", "setup_jupyter_mcp_integration();\n", "\n", "\n", "import stata_setup\n", "stata_setup.config(\"C:/Program Files/Stata18/\", \"se\", splash=False)" ] }, { "cell_type": "code", "execution_count": 2, "id": "23b92f73", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Stata Assignment 2 Solutions */\n", ". \n", ". /* 1. Read the data file */\n", ". infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_2.\n", "> dat\", clear\n", "(23,479 observations read)\n", "\n", ". \n", ". /* 2. Declare \"zero\" as a missing value for TRANTIME */\n", ". mvdecode TRANTIME, mv(0)\n", " TRANTIME: 12350 missing values generated\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Stata Assignment 2 Solutions */\n", "\n", "/* 1. Read the data file */\n", "infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_2.dat\", clear\n", "\n", "/* 2. Declare \"zero\" as a missing value for TRANTIME */\n", "mvdecode TRANTIME, mv(0)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d569512f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* 3. Create a new dichotomous poverty variable */\n", ". gen poor = (POVRATIO < 100)\n", "\n", ". label variable poor \"Below Poverty Line\"\n", "\n", ". label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\n", "\n", ". label values poor poorlbl\n", "\n", ". \n", ". /* Verify the new variable */\n", ". tab poor, missing\n", "\n", " Below |\n", " Poverty |\n", " Line | Freq. Percent Cum.\n", "------------+-----------------------------------\n", " Not Poor | 20,805 88.61 88.61\n", " Poor | 2,674 11.39 100.00\n", "------------+-----------------------------------\n", " Total | 23,479 100.00\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* 3. Create a new dichotomous poverty variable */\n", "gen poor = (POVRATIO < 100)\n", "label variable poor \"Below Poverty Line\"\n", "label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\n", "label values poor poorlbl\n", "\n", "/* Verify the new variable */\n", "tab poor, missing" ] }, { "cell_type": "code", "execution_count": 4, "id": "ff04e03d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Create a descriptive variable for the metropolitan area */\n", ". gen metro = \"\"\n", "(23,479 missing values generated)\n", "\n", ". replace metro = \"Duluth-Superior\" if METAREAD == 2240\n", "variable metro was str1 now str15\n", "(2,127 real changes made)\n", "\n", ". replace metro = \"Minneapolis-St. Paul\" if METAREAD == 5120\n", "variable metro was str15 now str20\n", "(21,352 real changes made)\n", "\n", ". label variable metro \"Metropolitan Area\"\n", "\n", ". \n", ". /* Check the distribution of observations by metropolitan area */\n", ". tab metro, missing\n", "\n", " Metropolitan Area | Freq. Percent Cum.\n", "---------------------+-----------------------------------\n", " Duluth-Superior | 2,127 9.06 9.06\n", "Minneapolis-St. Paul | 21,352 90.94 100.00\n", "---------------------+-----------------------------------\n", " Total | 23,479 100.00\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Create a descriptive variable for the metropolitan area */\n", "gen metro = \"\"\n", "replace metro = \"Duluth-Superior\" if METAREAD == 2240\n", "replace metro = \"Minneapolis-St. Paul\" if METAREAD == 5120\n", "label variable metro \"Metropolitan Area\"\n", "\n", "/* Check the distribution of observations by metropolitan area */\n", "tab metro, missing" ] }, { "cell_type": "code", "execution_count": 5, "id": "8e02aa49", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* 4. Analysis by metropolitan area */\n", ". \n", ". /* Minneapolis-St. Paul */\n", ". /* Histogram of commuting time */\n", ". histogram TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", "> title(\"Commuting Time in Minneapolis-St. Paul\") ///\n", "> xtitle(\"Travel Time to Work (minutes)\") ///\n", "> xlabel(0(15)120) ///\n", "> name(hist_msp, replace)\n", "(bin=40, start=1, width=3.7)\n", "\n", ". \n", ". /* Measures of central tendency and spread for commuting time */\n", ". tabstat TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", "> statistics(n mean sd min p25 p50 p75 max) columns(statistics)\n", "\n", " Variable | N Mean SD Min p25 p50\n", "-------------+------------------------------------------------------------\n", " TRANTIME | 10228 24.91504 18.8515 1 15 20\n", "--------------------------------------------------------------------------\n", "\n", " Variable | p75 Max\n", "-------------+--------------------\n", " TRANTIME | 30 149\n", "----------------------------------\n", "\n", ". \n" ] }, { "data": { "image/svg+xml": [ "\n", "\tStata Graph - hist_msp\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t0\n", "\t\n", "\t.01\n", "\t\n", "\t.02\n", "\t\n", "\t.03\n", "\t\n", "\t.04\n", "\t\n", "\t.05\n", "\tDensity\n", "\t\n", "\t\n", "\t0\n", "\t\n", "\t15\n", "\t\n", "\t30\n", "\t\n", "\t45\n", "\t\n", "\t60\n", "\t\n", "\t75\n", "\t\n", "\t90\n", "\t\n", "\t105\n", "\t\n", "\t120\n", "\tTravel Time to Work (minutes)\n", "\tCommuting Time in Minneapolis-St. Paul\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%stata\n", "/* 4. Analysis by metropolitan area */\n", "\n", "/* Minneapolis-St. Paul */\n", "/* Histogram of commuting time */\n", "histogram TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", " title(\"Commuting Time in Minneapolis-St. Paul\") ///\n", " xtitle(\"Travel Time to Work (minutes)\") ///\n", " xlabel(0(15)120) ///\n", " name(hist_msp, replace)\n", "\n", "/* Measures of central tendency and spread for commuting time */\n", "tabstat TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", " statistics(n mean sd min p25 p50 p75 max) columns(statistics)" ] }, { "cell_type": "code", "execution_count": 6, "id": "946488df", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Frequency distribution for poverty status in Minneapolis-St. Paul */\n", ". tab poor if metro == \"Minneapolis-St. Paul\", missing\n", "\n", " Below |\n", " Poverty |\n", " Line | Freq. Percent Cum.\n", "------------+-----------------------------------\n", " Not Poor | 18,988 88.93 88.93\n", " Poor | 2,364 11.07 100.00\n", "------------+-----------------------------------\n", " Total | 21,352 100.00\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Frequency distribution for poverty status in Minneapolis-St. Paul */\n", "tab poor if metro == \"Minneapolis-St. Paul\", missing" ] }, { "cell_type": "code", "execution_count": 7, "id": "845002cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Duluth-Superior */\n", ". /* Histogram of commuting time */\n", ". histogram TRANTIME if metro == \"Duluth-Superior\", ///\n", "> title(\"Commuting Time in Duluth-Superior\") ///\n", "> xtitle(\"Travel Time to Work (minutes)\") ///\n", "> xlabel(0(15)120) ///\n", "> name(hist_duluth, replace)\n", "(bin=29, start=1, width=5.1034483)\n", "\n", ". \n", ". /* Measures of central tendency and spread for commuting time */\n", ". tabstat TRANTIME if metro == \"Duluth-Superior\", ///\n", "> statistics(n mean sd min p25 p50 p75 max) columns(statistics)\n", "\n", " Variable | N Mean SD Min p25 p50\n", "-------------+------------------------------------------------------------\n", " TRANTIME | 901 22.51498 22.4792 1 10 15\n", "--------------------------------------------------------------------------\n", "\n", " Variable | p75 Max\n", "-------------+--------------------\n", " TRANTIME | 30 149\n", "----------------------------------\n", "\n", ". \n" ] }, { "data": { "image/svg+xml": [ "\n", "\tStata Graph - hist_duluth\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t0\n", "\t\n", "\t.01\n", "\t\n", "\t.02\n", "\t\n", "\t.03\n", "\t\n", "\t.04\n", "\tDensity\n", "\t\n", "\t\n", "\t0\n", "\t\n", "\t15\n", "\t\n", "\t30\n", "\t\n", "\t45\n", "\t\n", "\t60\n", "\t\n", "\t75\n", "\t\n", "\t90\n", "\t\n", "\t105\n", "\t\n", "\t120\n", "\tTravel Time to Work (minutes)\n", "\tCommuting Time in Duluth-Superior\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%stata\n", "/* Duluth-Superior */\n", "/* Histogram of commuting time */\n", "histogram TRANTIME if metro == \"Duluth-Superior\", ///\n", " title(\"Commuting Time in Duluth-Superior\") ///\n", " xtitle(\"Travel Time to Work (minutes)\") ///\n", " xlabel(0(15)120) ///\n", " name(hist_duluth, replace)\n", "\n", "/* Measures of central tendency and spread for commuting time */\n", "tabstat TRANTIME if metro == \"Duluth-Superior\", ///\n", " statistics(n mean sd min p25 p50 p75 max) columns(statistics)" ] }, { "cell_type": "code", "execution_count": 8, "id": "0145837b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Frequency distribution for poverty status in Duluth-Superior */\n", ". tab poor if metro == \"Duluth-Superior\", missing\n", "\n", " Below |\n", " Poverty |\n", " Line | Freq. Percent Cum.\n", "------------+-----------------------------------\n", " Not Poor | 1,817 85.43 85.43\n", " Poor | 310 14.57 100.00\n", "------------+-----------------------------------\n", " Total | 2,127 100.00\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Frequency distribution for poverty status in Duluth-Superior */\n", "tab poor if metro == \"Duluth-Superior\", missing" ] }, { "cell_type": "code", "execution_count": 9, "id": "9fe90c32", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* 5. Confidence Intervals by Metropolitan Area */\n", ". \n", ". /* Minneapolis-St. Paul */\n", ". /* 95% CI for mean commuting time */\n", ". ci mean TRANTIME if metro == \"Minneapolis-St. Paul\"\n", "\n", " Variable | Obs Mean Std. err. [95% conf. interval]\n", "-------------+---------------------------------------------------------------\n", " TRANTIME | 10,228 24.91504 .186402 24.54965 25.28042\n", "\n", ". \n", ". /* 95% CI for proportion of people who are poor */\n", ". ci proportions poor if metro == \"Minneapolis-St. Paul\"\n", "\n", " Binomial exact \n", " Variable | Obs Proportion Std. err. [95% conf. interval]\n", "-------------+---------------------------------------------------------------\n", " poor | 21,352 .1107156 .0021474 .1065367 .1150009\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* 5. Confidence Intervals by Metropolitan Area */\n", "\n", "/* Minneapolis-St. Paul */\n", "/* 95% CI for mean commuting time */\n", "ci mean TRANTIME if metro == \"Minneapolis-St. Paul\"\n", "\n", "/* 95% CI for proportion of people who are poor */\n", "ci proportions poor if metro == \"Minneapolis-St. Paul\"" ] }, { "cell_type": "code", "execution_count": 10, "id": "83dcc9cb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Duluth-Superior */\n", ". /* 95% CI for mean commuting time */\n", ". ci mean TRANTIME if metro == \"Duluth-Superior\"\n", "\n", " Variable | Obs Mean Std. err. [95% conf. interval]\n", "-------------+---------------------------------------------------------------\n", " TRANTIME | 901 22.51498 .7488908 21.04521 23.98476\n", "\n", ". \n", ". /* 95% CI for proportion of people who are poor */\n", ". ci proportions poor if metro == \"Duluth-Superior\"\n", "\n", " Binomial exact \n", " Variable | Obs Proportion Std. err. [95% conf. interval]\n", "-------------+---------------------------------------------------------------\n", " poor | 2,127 .1457452 .0076508 .1310107 .161463\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Duluth-Superior */\n", "/* 95% CI for mean commuting time */\n", "ci mean TRANTIME if metro == \"Duluth-Superior\"\n", "\n", "/* 95% CI for proportion of people who are poor */\n", "ci proportions poor if metro == \"Duluth-Superior\"" ] }, { "cell_type": "code", "execution_count": 12, "id": "4c06fdef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* 6. Manual calculation of confidence intervals */\n", ". \n", ". /* Minneapolis-St. Paul */\n", ". /* Get values needed for manual calculation of mean commuting time CI */\n", ". summarize TRANTIME if metro == \"Minneapolis-St. Paul\", detail\n", "\n", " TRANTIME\n", "-------------------------------------------------------------\n", " Percentiles Smallest\n", " 1% 2 1\n", " 5% 5 1\n", "10% 7 1 Obs 10,228\n", "25% 15 1 Sum of wgt. 10,228\n", "\n", "50% 20 Mean 24.91504\n", " Largest Std. dev. 18.8515\n", "75% 30 149\n", "90% 45 149 Variance 355.379\n", "95% 60 149 Skewness 2.883254\n", "99% 90 149 Kurtosis 17.69781\n", "\n", ". display \"Number of observations = \" r(N)\n", "Number of observations = 10228\n", "\n", ". display \"Mean = \" r(mean)\n", "Mean = 24.915037\n", "\n", ". display \"Standard deviation = \" r(sd)\n", "Standard deviation = 18.851499\n", "\n", ". display \"Standard error = \" r(sd) / sqrt(r(N))\n", "Standard error = .18640198\n", "\n", ". display \"t-value for 95% CI = \" invttail(r(N)-1, 0.025)\n", "t-value for 95% CI = 1.960196\n", "\n", ". display \"Lower CI bound = \" r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt\n", "> (r(N)))\n", "Lower CI bound = 24.549653\n", "\n", ". display \"Upper CI bound = \" r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt\n", "> (r(N)))\n", "Upper CI bound = 25.280422\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* 6. Manual calculation of confidence intervals */\n", "\n", "/* Minneapolis-St. Paul */\n", "/* Get values needed for manual calculation of mean commuting time CI */\n", "summarize TRANTIME if metro == \"Minneapolis-St. Paul\", detail\n", "display \"Number of observations = \" r(N)\n", "display \"Mean = \" r(mean)\n", "display \"Standard deviation = \" r(sd)\n", "display \"Standard error = \" r(sd) / sqrt(r(N))\n", "display \"t-value for 95% CI = \" invttail(r(N)-1, 0.025)\n", "display \"Lower CI bound = \" r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "display \"Upper CI bound = \" r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))" ] }, { "cell_type": "code", "execution_count": 13, "id": "c77a3991", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Manual calculation of poverty proportion CI for Minneapolis-St. Paul */\n", ". summarize poor if metro == \"Minneapolis-St. Paul\", detail\n", "\n", " Below Poverty Line\n", "-------------------------------------------------------------\n", " Percentiles Smallest\n", " 1% 0 0\n", " 5% 0 0\n", "10% 0 0 Obs 21,352\n", "25% 0 0 Sum of wgt. 21,352\n", "\n", "50% 0 Mean .1107156\n", " Largest Std. dev. .313787\n", "75% 0 1\n", "90% 1 1 Variance .0984623\n", "95% 1 1 Skewness 2.481259\n", "99% 1 1 Kurtosis 7.156649\n", "\n", ". display \"Number of observations = \" r(N)\n", "Number of observations = 21352\n", "\n", ". display \"Proportion poor = \" r(mean)\n", "Proportion poor = .11071562\n", "\n", ". display \"Standard error for proportion = \" sqrt((r(mean) * (1 - r(mean))) / r\n", "> (N))\n", "Standard error for proportion = .00214736\n", "\n", ". display \"z-value for 95% CI = \" invnormal(0.975)\n", "z-value for 95% CI = 1.959964\n", "\n", ". display \"Lower CI bound = \" r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 -\n", "> r(mean))) / r(N))\n", "Lower CI bound = .10650687\n", "\n", ". display \"Upper CI bound = \" r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 -\n", "> r(mean))) / r(N))\n", "Upper CI bound = .11492438\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Manual calculation of poverty proportion CI for Minneapolis-St. Paul */\n", "summarize poor if metro == \"Minneapolis-St. Paul\", detail\n", "display \"Number of observations = \" r(N)\n", "display \"Proportion poor = \" r(mean)\n", "display \"Standard error for proportion = \" sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "display \"z-value for 95% CI = \" invnormal(0.975)\n", "display \"Lower CI bound = \" r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "display \"Upper CI bound = \" r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))" ] }, { "cell_type": "code", "execution_count": 14, "id": "dbe01c87", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Duluth-Superior */\n", ". /* Manual calculation of mean commuting time CI */\n", ". summarize TRANTIME if metro == \"Duluth-Superior\", detail\n", "\n", " TRANTIME\n", "-------------------------------------------------------------\n", " Percentiles Smallest\n", " 1% 2 1\n", " 5% 5 1\n", "10% 5 1 Obs 901\n", "25% 10 1 Sum of wgt. 901\n", "\n", "50% 15 Mean 22.51498\n", " Largest Std. dev. 22.4792\n", "75% 30 149\n", "90% 45 149 Variance 505.3145\n", "95% 60 149 Skewness 3.447582\n", "99% 149 149 Kurtosis 18.23844\n", "\n", ". display \"Number of observations = \" r(N)\n", "Number of observations = 901\n", "\n", ". display \"Mean = \" r(mean)\n", "Mean = 22.514983\n", "\n", ". display \"Standard deviation = \" r(sd)\n", "Standard deviation = 22.479201\n", "\n", ". display \"Standard error = \" r(sd) / sqrt(r(N))\n", "Standard error = .74889078\n", "\n", ". display \"t-value for 95% CI = \" invttail(r(N)-1, 0.025)\n", "t-value for 95% CI = 1.9626033\n", "\n", ". display \"Lower CI bound = \" r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt\n", "> (r(N)))\n", "Lower CI bound = 21.045208\n", "\n", ". display \"Upper CI bound = \" r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt\n", "> (r(N)))\n", "Upper CI bound = 23.984759\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Duluth-Superior */\n", "/* Manual calculation of mean commuting time CI */\n", "summarize TRANTIME if metro == \"Duluth-Superior\", detail\n", "display \"Number of observations = \" r(N)\n", "display \"Mean = \" r(mean)\n", "display \"Standard deviation = \" r(sd)\n", "display \"Standard error = \" r(sd) / sqrt(r(N))\n", "display \"t-value for 95% CI = \" invttail(r(N)-1, 0.025)\n", "display \"Lower CI bound = \" r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "display \"Upper CI bound = \" r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))" ] }, { "cell_type": "code", "execution_count": 15, "id": "dd2280f9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Manual calculation of poverty proportion CI for Duluth-Superior */\n", ". summarize poor if metro == \"Duluth-Superior\", detail\n", "\n", " Below Poverty Line\n", "-------------------------------------------------------------\n", " Percentiles Smallest\n", " 1% 0 0\n", " 5% 0 0\n", "10% 0 0 Obs 2,127\n", "25% 0 0 Sum of wgt. 2,127\n", "\n", "50% 0 Mean .1457452\n", " Largest Std. dev. .3529335\n", "75% 0 1\n", "90% 1 1 Variance .1245621\n", "95% 1 1 Skewness 2.007959\n", "99% 1 1 Kurtosis 5.031901\n", "\n", ". display \"Number of observations = \" r(N)\n", "Number of observations = 2127\n", "\n", ". display \"Proportion poor = \" r(mean)\n", "Proportion poor = .14574518\n", "\n", ". display \"Standard error for proportion = \" sqrt((r(mean) * (1 - r(mean))) / r\n", "> (N))\n", "Standard error for proportion = .0076508\n", "\n", ". display \"z-value for 95% CI = \" invnormal(0.975)\n", "z-value for 95% CI = 1.959964\n", "\n", ". display \"Lower CI bound = \" r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 -\n", "> r(mean))) / r(N))\n", "Lower CI bound = .13074988\n", "\n", ". display \"Upper CI bound = \" r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 -\n", "> r(mean))) / r(N))\n", "Upper CI bound = .16074048\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Manual calculation of poverty proportion CI for Duluth-Superior */\n", "summarize poor if metro == \"Duluth-Superior\", detail\n", "display \"Number of observations = \" r(N)\n", "display \"Proportion poor = \" r(mean)\n", "display \"Standard error for proportion = \" sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "display \"z-value for 95% CI = \" invnormal(0.975)\n", "display \"Lower CI bound = \" r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "display \"Upper CI bound = \" r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))" ] }, { "cell_type": "code", "execution_count": 16, "id": "1b9e5f86", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". \n", ". /********************************************\n", "> STATA ASSIGNMENT 2: ANALYSIS OF ACS DATA\n", "> ********************************************/\n", ". \n", ". /* \n", "> American Community Survey (ACS) data analysis for:\n", "> - Minneapolis/St. Paul and Duluth/Superior metropolitan areas\n", "> - Variables: poverty status and commuting time\n", "> */\n", ". \n", ". /*******************************************\n", "> 1. Read the data file into STATA\n", "> *******************************************/\n", ". infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_2.\n", "> dat\", clear\n" ] }, { "ename": "SystemError", "evalue": "(23,479 observations read)\n\n. \n. /*******************************************\n> 2. Declare \"zero\" as missing value for TRANTIME\n> *******************************************/\n. mvdecode TRANTIME, mv(0)\n TRANTIME: 12350 missing values generated\n\n. \n. /*******************************************\n> 3. Create new dichotomous poverty variable\n> *******************************************/\n. gen poor = (POVRATIO < 100)\n\n. label variable poor \"Below Poverty Line\"\n\n. label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\nlabel poorlbl already defined\nr(110);\nr(110);\n", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mSystemError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[16], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39mrun_cell_magic(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstata\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/********************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mSTATA ASSIGNMENT 2: ANALYSIS OF ACS DATA\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m********************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mAmerican Community Survey (ACS) data analysis for:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Minneapolis/St. Paul and Duluth/Superior metropolitan areas\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Variables: poverty status and commuting time\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m1. Read the data file into STATA\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124minfix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m./stata_assignment_2.dat\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, clear\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m2. Declare \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mzero\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m as missing value for TRANTIME\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mmvdecode TRANTIME, mv(0)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m3. Create new dichotomous poverty variable\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mgen poor = (POVRATIO < 100)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlabel variable poor \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBelow Poverty Line\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlabel define poorlbl 0 \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNot Poor\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 1 \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPoor\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlabel values poor poorlbl\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Create a descriptive variable for the metropolitan area */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mgen metro = \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mreplace metro = \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m if METAREAD == 2240\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mreplace metro = \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m if METAREAD == 5120\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlabel variable metro \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMetropolitan Area\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m4. Analysis by metropolitan area\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mMinneapolis-St. Paul Analysis\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Histogram of commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mhistogram TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m title(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCommuting Time in Minneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m xtitle(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTravel Time to Work (minutes)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m xlabel(0(15)120) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m name(hist_msp, replace)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Measures of central tendency and spread for commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mtabstat TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m statistics(n mean sd min p25 p50 p75 max) columns(statistics)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Frequency distribution for poverty status */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mtab poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, missing\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mDuluth-Superior Analysis\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Histogram of commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mhistogram TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m title(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCommuting Time in Duluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m xtitle(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTravel Time to Work (minutes)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m xlabel(0(15)120) ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m name(hist_duluth, replace)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Measures of central tendency and spread for commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mtabstat TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, ///\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m statistics(n mean sd min p25 p50 p75 max) columns(statistics)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Frequency distribution for poverty status */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mtab poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, missing\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m5. Confidence Intervals by Metropolitan Area\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mMinneapolis-St. Paul Confidence Intervals\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* 95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI for mean commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mci mean TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* 95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI for proportion of people who are poor */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mci proportions poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mDuluth-Superior Confidence Intervals\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* 95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI for mean commuting time */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mci mean TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* 95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI for proportion of people who are poor */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mci proportions poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m6 & 7. Manual calculation of confidence intervals and comparison\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mMinneapolis-St. Paul Manual Calculations\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Manual calculation of mean commuting time CI */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124msummarize TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, detail\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal n_msp = r(N)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal mean_msp = r(mean)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal sd_msp = r(sd)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal se_msp = r(sd) / sqrt(r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal t_msp = invttail(r(N)-1, 0.025)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal lower_ci_msp = r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal upper_ci_msp = r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul Commuting Time Manual CI:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mN = `n_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, Mean = `mean_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SD = `sd_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SE = `se_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI = (`lower_ci_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, `upper_ci_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Manual calculation of poverty proportion CI */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124msummarize poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, detail\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal n_msp_poor = r(N)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal prop_msp = r(mean)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal se_prop_msp = sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal z = invnormal(0.975)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal lower_ci_prop_msp = r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal upper_ci_prop_msp = r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMinneapolis-St. Paul Poverty Proportion Manual CI:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mN = `n_msp_poor\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, Proportion = `prop_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SE = `se_prop_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI = (`lower_ci_prop_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, `upper_ci_prop_msp\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*----------------------------------------\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mDuluth-Superior Manual Calculations\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m----------------------------------------*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Manual calculation of mean commuting time CI */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124msummarize TRANTIME if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, detail\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal n_dul = r(N)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal mean_dul = r(mean)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal sd_dul = r(sd)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal se_dul = r(sd) / sqrt(r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal t_dul = invttail(r(N)-1, 0.025)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal lower_ci_dul = r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal upper_ci_dul = r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior Commuting Time Manual CI:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mN = `n_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, Mean = `mean_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SD = `sd_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SE = `se_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI = (`lower_ci_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, `upper_ci_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/* Manual calculation of poverty proportion CI */\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124msummarize poor if metro == \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m, detail\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal n_dul_poor = r(N)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal prop_dul = r(mean)\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal se_prop_dul = sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal lower_ci_prop_dul = r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mlocal upper_ci_prop_dul = r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuluth-Superior Poverty Proportion Manual CI:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mN = `n_dul_poor\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, Proportion = `prop_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, SE = `se_prop_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mdisplay \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m CI = (`lower_ci_prop_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m, `upper_ci_prop_dul\u001b[39m\u001b[38;5;130;01m\\'\u001b[39;00m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*******************************************\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m8. Interpretation of confidence intervals\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*******************************************/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m/*\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mINTERPRETATION OF CONFIDENCE INTERVALS:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mFor Minneapolis-St. Paul:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Commuting Time: We are 95\u001b[39m\u001b[38;5;132;01m% c\u001b[39;00m\u001b[38;5;124monfident that the true mean commuting time for people in \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m the Minneapolis-St. Paul area is between 24.55 and 25.28 minutes.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Poverty Rate: We are 95\u001b[39m\u001b[38;5;132;01m% c\u001b[39;00m\u001b[38;5;124monfident that the true proportion of people living below the \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m poverty line in the Minneapolis-St. Paul area is between 10.7\u001b[39m\u001b[38;5;132;01m% a\u001b[39;00m\u001b[38;5;124mnd 11.5\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mFor Duluth-Superior:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Commuting Time: We are 95\u001b[39m\u001b[38;5;132;01m% c\u001b[39;00m\u001b[38;5;124monfident that the true mean commuting time for people in \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m the Duluth-Superior area is between 21.05 and 23.98 minutes.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Poverty Rate: We are 95\u001b[39m\u001b[38;5;132;01m% c\u001b[39;00m\u001b[38;5;124monfident that the true proportion of people living below the \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m poverty line in the Duluth-Superior area is between 13.1\u001b[39m\u001b[38;5;132;01m% a\u001b[39;00m\u001b[38;5;124mnd 16.1\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mComparing the two metropolitan areas:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Commuting Time: The mean commuting time appears to be slightly higher in \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m Minneapolis-St. Paul than in Duluth-Superior (24.9 vs 22.5 minutes). However, the confidence \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m intervals overlap, suggesting this difference might not be statistically significant.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m- Poverty Rate: The poverty rate appears to be higher in Duluth-Superior than in Minneapolis-St. Paul \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m (14.6\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m vs 11.1\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m). The non-overlapping confidence intervals suggest this difference \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m is statistically significant.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mThese confidence intervals provide ranges within which we expect the true population parameters to lie\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mwith 95\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m probability, based on our sample data. They reflect both the point estimates \u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m(means or proportions) and the uncertainty in these estimates due to sampling variability.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m*/\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n", "File \u001b[1;32m~\\miniconda3\\Lib\\site-packages\\IPython\\core\\interactiveshell.py:2541\u001b[0m, in \u001b[0;36mInteractiveShell.run_cell_magic\u001b[1;34m(self, magic_name, line, cell)\u001b[0m\n\u001b[0;32m 2539\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuiltin_trap:\n\u001b[0;32m 2540\u001b[0m args \u001b[38;5;241m=\u001b[39m (magic_arg_s, cell)\n\u001b[1;32m-> 2541\u001b[0m result \u001b[38;5;241m=\u001b[39m fn(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 2543\u001b[0m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[0;32m 2544\u001b[0m \u001b[38;5;66;03m# when using magics with decorator @output_can_be_silenced\u001b[39;00m\n\u001b[0;32m 2545\u001b[0m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[0;32m 2546\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic\u001b[38;5;241m.\u001b[39mMAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n", "File \u001b[1;32mC:\\Program Files/Stata18/utilities\\pystata\\ipython\\stpymagic.py:276\u001b[0m, in \u001b[0;36mPyStataMagic.stata\u001b[1;34m(self, line, cell, local_ns)\u001b[0m\n\u001b[0;32m 274\u001b[0m _stata\u001b[38;5;241m.\u001b[39mrun(cell, quietly\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, inline\u001b[38;5;241m=\u001b[39m_config\u001b[38;5;241m.\u001b[39mstconfig[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgrshow\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[0;32m 275\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 276\u001b[0m _stata\u001b[38;5;241m.\u001b[39mrun(cell, quietly\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, inline\u001b[38;5;241m=\u001b[39m_config\u001b[38;5;241m.\u001b[39mstconfig[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgrshow\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[0;32m 278\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m-gw\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m args \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m-gh\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m args:\n\u001b[0;32m 279\u001b[0m _config\u001b[38;5;241m.\u001b[39mset_graph_size(gwidth, gheight)\n", "File \u001b[1;32mC:\\Program Files/Stata18/utilities\\pystata\\stata.py:325\u001b[0m, in \u001b[0;36mrun\u001b[1;34m(cmd, quietly, echo, inline)\u001b[0m\n\u001b[0;32m 323\u001b[0m \u001b[38;5;124m _stata_wrk2(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mqui include \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m + tmpf, None, False, 1)\u001b[39m\n\u001b[0;32m 324\u001b[0m \u001b[38;5;124m else:\u001b[39m\n\u001b[1;32m--> 325\u001b[0m \u001b[38;5;124m _stata_wrk2(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minclude \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m + tmpf, None, False, 1)\u001b[39m\n\u001b[0;32m 327\u001b[0m \u001b[38;5;124mif inline:\u001b[39m\n\u001b[0;32m 328\u001b[0m \u001b[38;5;124m if config.get_stipython()>=3:\u001b[39m\n", "File \u001b[1;32mC:\\Program Files/Stata18/utilities\\pystata\\stata.py:116\u001b[0m, in \u001b[0;36m_stata_wrk2\u001b[1;34m(cmd, real_cmd, colon, mode)\u001b[0m\n\u001b[0;32m 114\u001b[0m err \u001b[38;5;241m=\u001b[39m callback[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m 115\u001b[0m callback\u001b[38;5;241m.\u001b[39mclear()\n\u001b[1;32m--> 116\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mSystemError\u001b[39;00m(err)\n\u001b[0;32m 117\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m 118\u001b[0m outputter\u001b[38;5;241m.\u001b[39mdone()\n", "\u001b[1;31mSystemError\u001b[0m: (23,479 observations read)\n\n. \n. /*******************************************\n> 2. Declare \"zero\" as missing value for TRANTIME\n> *******************************************/\n. mvdecode TRANTIME, mv(0)\n TRANTIME: 12350 missing values generated\n\n. \n. /*******************************************\n> 3. Create new dichotomous poverty variable\n> *******************************************/\n. gen poor = (POVRATIO < 100)\n\n. label variable poor \"Below Poverty Line\"\n\n. label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\nlabel poorlbl already defined\nr(110);\nr(110);\n" ] } ], "source": [ "%%stata\n", "\n", "/********************************************\n", "STATA ASSIGNMENT 2: ANALYSIS OF ACS DATA\n", "********************************************/\n", "\n", "/* \n", "American Community Survey (ACS) data analysis for:\n", "- Minneapolis/St. Paul and Duluth/Superior metropolitan areas\n", "- Variables: poverty status and commuting time\n", "*/\n", "\n", "/*******************************************\n", "1. Read the data file into STATA\n", "*******************************************/\n", "infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_2.dat\", clear\n", "\n", "/*******************************************\n", "2. Declare \"zero\" as missing value for TRANTIME\n", "*******************************************/\n", "mvdecode TRANTIME, mv(0)\n", "\n", "/*******************************************\n", "3. Create new dichotomous poverty variable\n", "*******************************************/\n", "gen poor = (POVRATIO < 100)\n", "label variable poor \"Below Poverty Line\"\n", "label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\n", "label values poor poorlbl\n", "\n", "/* Create a descriptive variable for the metropolitan area */\n", "gen metro = \"\"\n", "replace metro = \"Duluth-Superior\" if METAREAD == 2240\n", "replace metro = \"Minneapolis-St. Paul\" if METAREAD == 5120\n", "label variable metro \"Metropolitan Area\"\n", "\n", "/*******************************************\n", "4. Analysis by metropolitan area\n", "*******************************************/\n", "\n", "/*----------------------------------------\n", "Minneapolis-St. Paul Analysis\n", "----------------------------------------*/\n", "/* Histogram of commuting time */\n", "histogram TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", " title(\"Commuting Time in Minneapolis-St. Paul\") ///\n", " xtitle(\"Travel Time to Work (minutes)\") ///\n", " xlabel(0(15)120) ///\n", " name(hist_msp, replace)\n", "\n", "/* Measures of central tendency and spread for commuting time */\n", "tabstat TRANTIME if metro == \"Minneapolis-St. Paul\", ///\n", " statistics(n mean sd min p25 p50 p75 max) columns(statistics)\n", "\n", "/* Frequency distribution for poverty status */\n", "tab poor if metro == \"Minneapolis-St. Paul\", missing\n", "\n", "/*----------------------------------------\n", "Duluth-Superior Analysis\n", "----------------------------------------*/\n", "/* Histogram of commuting time */\n", "histogram TRANTIME if metro == \"Duluth-Superior\", ///\n", " title(\"Commuting Time in Duluth-Superior\") ///\n", " xtitle(\"Travel Time to Work (minutes)\") ///\n", " xlabel(0(15)120) ///\n", " name(hist_duluth, replace)\n", "\n", "/* Measures of central tendency and spread for commuting time */\n", "tabstat TRANTIME if metro == \"Duluth-Superior\", ///\n", " statistics(n mean sd min p25 p50 p75 max) columns(statistics)\n", "\n", "/* Frequency distribution for poverty status */\n", "tab poor if metro == \"Duluth-Superior\", missing\n", "\n", "/*******************************************\n", "5. Confidence Intervals by Metropolitan Area\n", "*******************************************/\n", "\n", "/*----------------------------------------\n", "Minneapolis-St. Paul Confidence Intervals\n", "----------------------------------------*/\n", "/* 95% CI for mean commuting time */\n", "ci mean TRANTIME if metro == \"Minneapolis-St. Paul\"\n", "\n", "/* 95% CI for proportion of people who are poor */\n", "ci proportions poor if metro == \"Minneapolis-St. Paul\"\n", "\n", "/*----------------------------------------\n", "Duluth-Superior Confidence Intervals\n", "----------------------------------------*/\n", "/* 95% CI for mean commuting time */\n", "ci mean TRANTIME if metro == \"Duluth-Superior\"\n", "\n", "/* 95% CI for proportion of people who are poor */\n", "ci proportions poor if metro == \"Duluth-Superior\"\n", "\n", "/*******************************************\n", "6 & 7. Manual calculation of confidence intervals and comparison\n", "*******************************************/\n", "\n", "/*----------------------------------------\n", "Minneapolis-St. Paul Manual Calculations\n", "----------------------------------------*/\n", "/* Manual calculation of mean commuting time CI */\n", "summarize TRANTIME if metro == \"Minneapolis-St. Paul\", detail\n", "local n_msp = r(N)\n", "local mean_msp = r(mean)\n", "local sd_msp = r(sd)\n", "local se_msp = r(sd) / sqrt(r(N))\n", "local t_msp = invttail(r(N)-1, 0.025)\n", "local lower_ci_msp = r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "local upper_ci_msp = r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "\n", "display \"Minneapolis-St. Paul Commuting Time Manual CI:\"\n", "display \"N = `n_msp', Mean = `mean_msp', SD = `sd_msp', SE = `se_msp'\"\n", "display \"95% CI = (`lower_ci_msp', `upper_ci_msp')\"\n", "\n", "/* Manual calculation of poverty proportion CI */\n", "summarize poor if metro == \"Minneapolis-St. Paul\", detail\n", "local n_msp_poor = r(N)\n", "local prop_msp = r(mean)\n", "local se_prop_msp = sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "local z = invnormal(0.975)\n", "local lower_ci_prop_msp = r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "local upper_ci_prop_msp = r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "\n", "display \"Minneapolis-St. Paul Poverty Proportion Manual CI:\"\n", "display \"N = `n_msp_poor', Proportion = `prop_msp', SE = `se_prop_msp'\"\n", "display \"95% CI = (`lower_ci_prop_msp', `upper_ci_prop_msp')\"\n", "\n", "/*----------------------------------------\n", "Duluth-Superior Manual Calculations\n", "----------------------------------------*/\n", "/* Manual calculation of mean commuting time CI */\n", "summarize TRANTIME if metro == \"Duluth-Superior\", detail\n", "local n_dul = r(N)\n", "local mean_dul = r(mean)\n", "local sd_dul = r(sd)\n", "local se_dul = r(sd) / sqrt(r(N))\n", "local t_dul = invttail(r(N)-1, 0.025)\n", "local lower_ci_dul = r(mean) - invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "local upper_ci_dul = r(mean) + invttail(r(N)-1, 0.025) * (r(sd) / sqrt(r(N)))\n", "\n", "display \"Duluth-Superior Commuting Time Manual CI:\"\n", "display \"N = `n_dul', Mean = `mean_dul', SD = `sd_dul', SE = `se_dul'\"\n", "display \"95% CI = (`lower_ci_dul', `upper_ci_dul')\"\n", "\n", "/* Manual calculation of poverty proportion CI */\n", "summarize poor if metro == \"Duluth-Superior\", detail\n", "local n_dul_poor = r(N)\n", "local prop_dul = r(mean)\n", "local se_prop_dul = sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "local lower_ci_prop_dul = r(mean) - invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "local upper_ci_prop_dul = r(mean) + invnormal(0.975) * sqrt((r(mean) * (1 - r(mean))) / r(N))\n", "\n", "display \"Duluth-Superior Poverty Proportion Manual CI:\"\n", "display \"N = `n_dul_poor', Proportion = `prop_dul', SE = `se_prop_dul'\"\n", "display \"95% CI = (`lower_ci_prop_dul', `upper_ci_prop_dul')\"\n", "\n", "/*******************************************\n", "8. Interpretation of confidence intervals\n", "*******************************************/\n", "\n", "/*\n", "INTERPRETATION OF CONFIDENCE INTERVALS:\n", "\n", "For Minneapolis-St. Paul:\n", "- Commuting Time: We are 95% confident that the true mean commuting time for people in \n", " the Minneapolis-St. Paul area is between 24.55 and 25.28 minutes.\n", "- Poverty Rate: We are 95% confident that the true proportion of people living below the \n", " poverty line in the Minneapolis-St. Paul area is between 10.7% and 11.5%.\n", "\n", "For Duluth-Superior:\n", "- Commuting Time: We are 95% confident that the true mean commuting time for people in \n", " the Duluth-Superior area is between 21.05 and 23.98 minutes.\n", "- Poverty Rate: We are 95% confident that the true proportion of people living below the \n", " poverty line in the Duluth-Superior area is between 13.1% and 16.1%.\n", "\n", "Comparing the two metropolitan areas:\n", "- Commuting Time: The mean commuting time appears to be slightly higher in \n", " Minneapolis-St. Paul than in Duluth-Superior (24.9 vs 22.5 minutes). However, the confidence \n", " intervals overlap, suggesting this difference might not be statistically significant.\n", "- Poverty Rate: The poverty rate appears to be higher in Duluth-Superior than in Minneapolis-St. Paul \n", " (14.6% vs 11.1%). The non-overlapping confidence intervals suggest this difference \n", " is statistically significant.\n", "\n", "These confidence intervals provide ranges within which we expect the true population parameters to lie\n", "with 95% probability, based on our sample data. They reflect both the point estimates \n", "(means or proportions) and the uncertainty in these estimates due to sampling variability.\n", "*/" ] }, { "cell_type": "code", "execution_count": 17, "id": "9ab3fa7c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", ". /* Save the do file */\n", ". /* Note: In an actual assignment submission, you would save this to a local f\n", "> ile */\n", ". file close _all\n", "\n", ". file open mydo using \"stata_assignment_2.do\", write replace\n", "(file stata_assignment_2.do not found)\n", "\n", ". file write mydo ///\n", "> `\"/********************************************\"' _n ///\n", "> `\"STATA ASSIGNMENT 2: ANALYSIS OF ACS DATA\"' _n ///\n", "> `\"********************************************/\"' _n _n ///\n", "> `\"/* \"' _n ///\n", "> `\"American Community Survey (ACS) data analysis for:\"' _n ///\n", "> `\"- Minneapolis/St. Paul and Duluth/Superior metropolitan areas\"' _n ///\n", "> `\"- Variables: poverty status and commuting time\"' _n ///\n", "> `\"*/\"' _n _n ///\n", "> `\"/*******************************************\"' _n ///\n", "> `\"1. Read the data file into STATA\"' _n ///\n", "> `\"*******************************************/\"' _n ///\n", "> `\"infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_\n", "> 2.dat\", clear\"' _n _n ///\n", "> `\"/*******************************************\"' _n ///\n", "> `\"2. Declare \"zero\" as missing value for TRANTIME\"' _n ///\n", "> `\"*******************************************/\"' _n ///\n", "> `\"mvdecode TRANTIME, mv(0)\"' _n _n ///\n", "> `\"/*******************************************\"' _n ///\n", "> `\"3. Create new dichotomous poverty variable\"' _n ///\n", "> `\"*******************************************/\"' _n ///\n", "> `\"gen poor = (POVRATIO < 100)\"' _n ///\n", "> `\"label variable poor \"Below Poverty Line\"\"' _n ///\n", "> `\"label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\"' _n ///\n", "> `\"label values poor poorlbl\"' _n _n ///\n", "> `\"/* Create a descriptive variable for the metropolitan area */\"' _n ///\n", "> `\"gen metro = \"\"\"' _n ///\n", "> `\"replace metro = \"Duluth-Superior\" if METAREAD == 2240\"' _n ///\n", "> `\"replace metro = \"Minneapolis-St. Paul\" if METAREAD == 5120\"' _n ///\n", "> `\"label variable metro \"Metropolitan Area\"\"' _n _n\n", "\n", ". file close mydo\n", "\n", ". \n" ] } ], "source": [ "%%stata\n", "/* Save the do file */\n", "/* Note: In an actual assignment submission, you would save this to a local file */\n", "file close _all\n", "file open mydo using \"stata_assignment_2.do\", write replace\n", "file write mydo ///\n", "`\"/********************************************\"' _n ///\n", "`\"STATA ASSIGNMENT 2: ANALYSIS OF ACS DATA\"' _n ///\n", "`\"********************************************/\"' _n _n ///\n", "`\"/* \"' _n ///\n", "`\"American Community Survey (ACS) data analysis for:\"' _n ///\n", "`\"- Minneapolis/St. Paul and Duluth/Superior metropolitan areas\"' _n ///\n", "`\"- Variables: poverty status and commuting time\"' _n ///\n", "`\"*/\"' _n _n ///\n", "`\"/*******************************************\"' _n ///\n", "`\"1. Read the data file into STATA\"' _n ///\n", "`\"*******************************************/\"' _n ///\n", "`\"infix METAREAD 4-7 POVRATIO 18-20 TRANTIME 21-23 using \"./stata_assignment_2.dat\", clear\"' _n _n ///\n", "`\"/*******************************************\"' _n ///\n", "`\"2. Declare \"zero\" as missing value for TRANTIME\"' _n ///\n", "`\"*******************************************/\"' _n ///\n", "`\"mvdecode TRANTIME, mv(0)\"' _n _n ///\n", "`\"/*******************************************\"' _n ///\n", "`\"3. Create new dichotomous poverty variable\"' _n ///\n", "`\"*******************************************/\"' _n ///\n", "`\"gen poor = (POVRATIO < 100)\"' _n ///\n", "`\"label variable poor \"Below Poverty Line\"\"' _n ///\n", "`\"label define poorlbl 0 \"Not Poor\" 1 \"Poor\"\"' _n ///\n", "`\"label values poor poorlbl\"' _n _n ///\n", "`\"/* Create a descriptive variable for the metropolitan area */\"' _n ///\n", "`\"gen metro = \"\"\"' _n ///\n", "`\"replace metro = \"Duluth-Superior\" if METAREAD == 2240\"' _n ///\n", "`\"replace metro = \"Minneapolis-St. Paul\" if METAREAD == 5120\"' _n ///\n", "`\"label variable metro \"Metropolitan Area\"\"' _n _n\n", "file close mydo" ] }, { "cell_type": "markdown", "id": "113b3eca", "metadata": {}, "source": [ "%%markdown\n", "# ACS Data Analysis Summary\n", "\n", "In this assignment, we analyzed data from the American Community Survey (ACS) for two metropolitan areas: Minneapolis/St. Paul and Duluth/Superior. We focused on two key variables: commuting time and poverty status.\n", "\n", "## Key Findings\n", "\n", "### Commuting Time Analysis\n", "\n", "**Minneapolis-St. Paul**:\n", "- Mean commuting time: 24.92 minutes\n", "- Standard deviation: 18.85 minutes\n", "- 95% CI for mean commuting time: (24.55, 25.28) minutes\n", "\n", "**Duluth-Superior**:\n", "- Mean commuting time: 22.51 minutes\n", "- Standard deviation: 22.48 minutes\n", "- 95% CI for mean commuting time: (21.05, 23.98) minutes\n", "\n", "### Poverty Analysis\n", "\n", "**Minneapolis-St. Paul**:\n", "- Proportion below poverty line: 11.07%\n", "- 95% CI for poverty rate: (10.65%, 11.50%)\n", "\n", "**Duluth-Superior**:\n", "- Proportion below poverty line: 14.57%\n", "- 95% CI for poverty rate: (13.10%, 16.15%)\n", "\n", "## Comparison Between Metropolitan Areas\n", "\n", "1. **Commuting Time**: \n", " - Minneapolis-St. Paul residents have a slightly longer average commute time (24.92 minutes) compared to Duluth-Superior residents (22.51 minutes).\n", " - The confidence intervals show some overlap, indicating that this difference might not be statistically significant.\n", "\n", "2. **Poverty Rate**:\n", " - Duluth-Superior has a higher poverty rate (14.57%) compared to Minneapolis-St. Paul (11.07%).\n", " - The non-overlapping confidence intervals suggest this difference is statistically significant.\n", "\n", "## Interpretation of Confidence Intervals\n", "\n", "The 95% confidence intervals tell us that if we were to repeat this sampling process many times, 95% of the resulting intervals would contain the true population parameter (either the mean commuting time or the poverty rate).\n", "\n", "For example, we can state with 95% confidence that:\n", "- The true mean commuting time in Minneapolis-St. Paul is between 24.55 and 25.28 minutes.\n", "- The true poverty rate in Duluth-Superior is between 13.10% and 16.15%.\n", "\n", "These intervals provide not just point estimates but also indicate the precision of our estimates, which is important for making reliable inferences about the population." ] }, { "cell_type": "markdown", "id": "31ae765f", "metadata": {}, "source": [ "%%markdown\n", "## Steps Completed in the Assignment\n", "\n", "1. **Data Import**: Successfully imported the ACS data from `stata_assignment_2.dat` using the correct column specifications.\n", "\n", "2. **Data Cleaning**: Recoded zero values in the commuting time variable as missing values.\n", "\n", "3. **Variable Creation**: Generated a new dichotomous poverty variable based on the poverty ratio threshold of 100.\n", "\n", "4. **Descriptive Analysis**: Produced histograms, measures of central tendency, and frequency distributions for both metropolitan areas.\n", "\n", "5. **Statistical Inference**: Calculated and interpreted 95% confidence intervals for both mean commuting time and poverty rates.\n", "\n", "6. **Manual Calculations**: Verified Stata's confidence interval calculations with manual calculations, confirming that both methods yield the same results.\n", "\n", "7. **Interpretation**: Provided substantive interpretations of the confidence intervals, including comparisons between the two metropolitan areas.\n", "\n", "The analysis shows clear demographic and economic differences between the two metropolitan areas, with evidence of higher poverty rates in Duluth-Superior compared to Minneapolis-St. Paul, despite slightly shorter commuting times in the former." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }