Author: espin086

Accessing the U.S. Census API and Creating Heat Maps in R

The United States Census is rich with information that can be used by economist to understand demographic and social trends.  A popular way of presenting data from the U.S. Census data by plotting it on a map.  The goal of this post is obtain data from the U.S. Census via an API connection and plotting the data on a map using R. The reason for accessing data via an API as opposed to going to the U.S. Census website is speed, ease of querying the database, and repeatbility which I will demonstrate through a few examples.  Demonstrating R’s mapping feature provides a good start to learning how to map data in general. ACCESSING DATA VIA THE CENSUS API In order to access the Census API using R you need to download and install the ACS package in addition to going to requesting a secret key from the U.S. Census. This document contains the steps that got me started and contains more detailed information than is found in this post if you are interested in getting an in-depth knowledge of the ACS package. Once you’ve installed the package and requested your API key from the Census you are ready to get started, type the following commands to gain access to the U.S. Census database in addition to installing other libraries used in this post to manipulate data and create the...

Read More

Who Cheats on their Spouse and What Makes Marriages Happy? – Multinomial Logit and Probit Regression Analysis

BACKGROUND In 1978, Ray C. Fair from Yale University, extended the microeconomic framework to study why people have affairs. The paper creates an econometric model grounded in Utility theory. In economics, Utility Theory describes how people consume goods/services based off their costs, price and availability of substitute goods, price and availability of complementary goods, and explains the well-being people derive from multiple goods consumption. This analysis and theory are extended to the consumption of multiple relationships (i.e. affairs) in Fair’s paper. The goal of this post is to estimate a probability model, similar to what Fair(1978) used in his paper, that will quantify what socioeconomic factors impact the probability of affairs for married couples. This post will also extend on Fair’s work by analyzing what factors increase happiness in a marriage, which he found to have a significant influences on whether or not a person had an extramarital affair. ORIGINAL PAPER, DATA, AND STATA PROGRAM USED IN THIS POST Original Paper (Fair 1978) Data Affairs (Fair 1978) STATA PROGRAM – AFFAIRS (1978)   The data are survey data from Psychology Today (1969) and Redbook (1974) magazines. The variables in the data are as follows and contain the following names and labels. PROBIT REGRESSION MODEL FOR AFFAIRS The probit regression model assumes that the regression errors will be normally distributed, or more formally: The results from this regression model are...

Read More

Enter Email and Hit Enter

Twitter Timeline

Learn the Basics

Master the Material

For Fun