Title: | Companion Package to Probability and Statistics for Economics and Business |
---|---|
Description: | Utilities for multiple hypothesis testing, companion datasets from "Probability and Statistics for Economics and Business: An Introduction Using R" by Jason Abrevaya (MIT Press, under contract). |
Authors: | Jason Abrevaya [aut, cph], Nathan Gardner Hattersley [aut, cre] |
Maintainer: | Nathan Gardner Hattersley <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.1 |
Built: | 2024-11-01 11:17:38 UTC |
Source: | https://github.com/cran/probstats4econ |
Data on eBay auctions, based upon the paper "Econometrics of Auctions by Least Squares" by Leonardo Rezende, Journal of Applied Econometrics, 2008, 23:925-948. The dataset consists of eBay auctions for Apple iPod mini devices in June and July 2006, limited to only auctions for the 4GB models.
auctions
auctions
auctions
A data frame with 684 rows and 14 columns:
eBay auction ID number
Number of bidders
Final sales price
Seller's positive feedback percentage (e.g., 90 = 90%)
Seller's feedback score (number of feedbacks received)
Reserve price set by seller (value of 0.01 if no reserve price)
1 if iPod is pink, 0 otherwise
1 if iPod is blue, 0 otherwise
1 if iPod is silver, 0 otherwise
1 if iPod is green, 0 otherwise
1 if iPod is another color, 0 otherwise
1 if condition listed is new, 0 otherwise
1 if condition listed is used, 0 otherwise
1 if condition listed is refurbished, 0 otherwise
https://journaldata.zbw.eu/dataset/econometrics-of-auctions-by-least-squares
Data on the names of all babies born in the United States in 2022, as provided by the Social Security Administration. Each observation corresponds to a specific name and gender, with a count of that name provided. For confidentiality reasons, the minimum count for any name is 5. All other names (with fewer than 5 occurrences in the U.S.) are included within the observation having "OTHER" as the name. There are two "OTHER" observations, one for female babies and one for male babies. Data are sorted alphabetically by name.
babynames
babynames
babynames
A data frame with 31915 rows and 3 columns:
Baby's name
F if female, M if male
Number of babies with name and gender
https://www.ssa.gov/oact/babynames/limits.html
Data on 2022 attendance for Major League Baseball teams
baseball
baseball
baseball
A data frame with 30 rows and 9 columns:
Team name
Average home game attendance
Average road game attendance
Team winning percentage in 2022
Team winning percentage in 2021
1 if team made playoffs in 2021, 0 otherwise
Capacity of home stadium
Population of team's metropolitan area (2020)
Total team payroll in 2022 (in millions of dollars)
various
Data on birth outcomes in the United States for December 2021 births where mother's age is between 25 and 35 (inclusive), limited to singleton births, mother's first child, and having non-missing values for relevant variables
births
births
births
A data frame with 50,249 rows and 20 columns:
Birth time during day (in minutes, range is 0 to 2399)
Day of week of birth (1=Sunday, 2=Monday, ..., 7=Saturday)
Mother's age (in years)
1 if mother is not a HS graduate, 0 otherwise
1 if mother is HS graduate and has no add'l education, 0 otherwise
1 if mother completed some college, 0 otherwise
1 if mother is 4-year college graduate, 0 otherwise
1 if mother is married, 0 otherwise
1 if mother smoked during first trimester, 0 otherwise
1 if mother smoked during second trimester, 0 otherwise
1 if mother smoked during third trimester, 0 otherwise
1 if mother smoked before pregnancy, 0 otherwise
1 if mother smoked during pregnancy (any trimester), 0 otherwise
1 if first prenatal care during first trimester, 0 otherwise
1 if first prenatal care during second trimester, 0 otherwise
1 if first prenatal care during third trimester, 0 otherwise
1 if no prenatal care visit, 0 otherwise
1 if baby is a boy, 0 otherwise
Birthweight (in grams)
Birthweight (in pounds)
https://www.nber.org/research/data/vital-statistics-natality-birth-data
Data on daily prices and returns for Bitcoin during 2020 and 2021
bitcoin
bitcoin
bitcoin
A data frame with 364 rows and 268 columns:
Date
Highest price (in dollars)
Lowest price (in dollars)
End-of-day price (in dollars)
Daily return, based on end-of-day prices
Data on the purchase behavior of customers at a specific market. The dataset consists of customers who purchased one of five candy-bar brands in their previous visit to the market and records whether or not they make a purchase during this visit and, if so, which brand they purchase. The dataset is adapted from the full dataset that is referenced in the source citation.
brands
brands
brands
A data frame with 14,560 rows and 3 columns:
1 if customer makes a purchase, 0 otherwise
Brand purchased (1 through 5), 0 if no purchase
Brand purchased (1 through 5) during last visit
Data on cigarette prices and taxes in 2019 for the 50 U.S. states plus the District of Columbia
cigdata
cigdata
cigdata
A data frame with 51 rows and 9 columns:
State abbreviation
State name
Average price per pack (in dollars)
Annual sales, packs per capita
Total annual tax revenue (in dollars)
State tax per pack (in dollars)
1 if tobacco production > 20m pounds, 0 otherwise
https://healthdata.gov/dataset/The-Tax-Burden-on-Tobacco-1970-2019/etts-u9ii
Data on congressional election outcomes in the United States between 1948 and 1990, based upon the paper "Do Voters Affect or Elect Policies? Evidence from the U.S. House" by David S. Lee, Enrico Moretti, Matthew J. Butler, 2004, Quarterly Journal of Economics, 119: 807-859. This sample is restricted to elections where (i) the incumbent is running for re-election and (ii) are not running unopposed. There are 9,788 observations available, and demographic variables are available for 6,774 of the observations.
congress
congress
congress
A data frame with 9,788 rows and 15 columns:
State code (ICPSR coding)
District code
Number of votes for Democrat candidate
Number of votes for Republican candidate
Year of election
Percentage of vote for Democrat candidate
Percentage of vote for Democrat candidate in last election
Population of Congressional district
Median (nominal) income of Congressional district
Percentage of Congressional district that is urban
Percentage of Congressional district that is black
Percentage of Congressional district that is HS graduates
Voting population of Congressional district
1 if Democrat wins election (demvoteshare>0.5), 0 otherwise
1 if Democrat won last election (lagdemvoteshare>0.5), 0 otherwise
https://eml.berkeley.edu/%7Emoretti/data3.html
A subsample of the 2019 Current Population Survey (CPS) consisting of data on individuals aged 30 to 59 (inclusive)
cps
cps
cps
A data frame with 4,013 rows and 17 columns:
Two-character state code, including DC
Gender (Male, Female)
Metropolitan-area (Metro, Non-Metro)
Race category (Black, White, Other)
Hispanic (Hispanic, Non-hispanic)
Marital status (Married, Divorced, Widowed, Never married)
Labor-force status (Employed, Unemployed, Not in LF)
Earnings include overtime, tips, and/or commissions (Yes, No)
Hourly-worker status (Hourly, Non-hourly)
Union status (Union, Non-union)
Age (in years)
Hours worked last week
Number of weeks unemployed
Hourly wage (in dollars); only for hourly employees
Earnings last week (in dollars)
Number of children in household
Highest education level attained (in years)
https://www.census.gov/programs-surveys/cps/data/datasets.html
Data on the results from "dictator games" played in an experimental study, based on the paper "Giving and taking in dictator games – differences by gender? A replication study of Chowdhury et al.", Journal of Comments and Replications in Economics, 2023. Each observation corresponds to one play of the game. Earnings are for the dictator. Two game variants are the "giving game" (dictator starts with endowment) and "taking game" (recipient starts with endowment).
dictator
dictator
dictator
A data frame with 137 rows and 5 columns:
Earnings of the dictator (between 0 and 10)
1 if giving game, 0 otherwise
1 if taking game, 0 otherwise
1 if dictator is female, 0 otherwise
1 if recipient is female, 0 otherwise
https://journaldata.zbw.eu/dataset/giving-and-taking-in-dictator-games-replication
Data on two exam scores for 77 university students
exams
exams
exams
A data frame with 77 rows and 2 columns:
Score (out of 100) on the first exam
Score (out of 100) on the second exam
Data on house sales in Ames, Iowa between 2006 and 2010. The dataset is limited to one-family homes with public utilities and excludes new home sales.
houseprices
houseprices
houseprices
A data frame with 973 rows and 16 columns:
Area of lot (in square feet)
Overall home quality (scale 1-10, 10 best)
Year house was built
Year house was remodeled (equal to yearbuilt if never)
Area of finished basement (in square feet, 0 if no finished basement)
Total non-basement living area (in square feet)
Number of full bathrooms
Number of half bathrooms
Number of non-basement bedrooms
Number of non-basement rooms (not including bathrooms)
Number of fireplaces
Size of garage (0 if no garage)
Month house sold (1=Jan,...,12=Dec)
Year house sold
Sales price of house (in dollars)
1 if house has central air, 0 otherwise
https://www.kaggle.com/competitions/house-prices-advanced-regression-techniques/data
Data on healthcare utilization and expenditures for adults 50 years and older in the United States, taken from the Health and Retirement Study (HRS) and Asset and Health Dynamics Among the Oldest Old (AHEAD). Data was originally used in the paper "On the distribution and dynamics of health care costs" by Eric French and John Bailey Jones, 2004, Journal of Applied Econometrics, 19: 705-721. This dataset is restricted to non-married individuals in the year 2000.
hrs
hrs
hrs
A data frame with 6,052 rows and 14 columns:
Age (in years)
Total assets (in dollars); bottom-coded at $20,000
Number of doctor visits
Drug costs (in dollars)
Income (in dollars); bottom-coded at $5,000
Number of nights spent in hospital
1 if insurance is private or employee-provided, 0 otherwise
1 if insurance is Medicare, 0 otherwise
1 if insurance is Medicaid, 0 otherwise
1 if no health insurance, 0 otherwise
1 if male, 0 otherwise
Total medical costs (in dollars)
1 if did not take prescription drugs for financial reasons, 0 otherwise
Total out-of-pocket medical costs (in dollars)
https://journaldata.zbw.eu/dataset/on-the-distribution-and-dynamics-of-health-care-costs
Data on inflation rates for 45 countries for a ten-year period (2010-2019).
inflation
inflation
inflation
A data frame with 450 rows and 3 columns:
Country abbreviation
Year
Annual inflation rate (change in CPI)
https://data.oecd.org/price/inflation-cpi.htm
Data on individual inflation expectations, based on the paper: "Measuring consumer uncertainty about future inflation," by Wandi Bruine de Bruin, Charles F. Manski, Giorgio Topa, Wilbert van der Klaauw, 2011, Journal of Applied Econometrics, 26: 454-478. This dataset has only the observations with point estimates of inflation for individuals between 30 and 70 years of age. The survey took place in 2007 and 2008. The actual inflation, for benchmark, was 3.2% in 2006, 2.9% in 2007, and 3.8% in 2008.
inflation_expectations
inflation_expectations
inflation_expectations
A data frame with 290 rows and 6 columns:
Individual prediction of inflation next year (integer; e.g. 10=10%)
Age (in years)
Financial literacy test score (out of 12 points)
1 if male, 0 otherwise
1 if college graduate, 0 otherwise
1 if family income > $75,000, 0 otherwise
https://journaldata.zbw.eu/dataset/measuring-consumer-uncertainty-about-future-inflation
linear_combination
takes a set of regression results
and a vector representing a linear combination of the
parameters and returns the estimate, standard error,
and p-value for the null hypothesis that the linear
combination is equal to zero.
linear_combination(regresults, R)
linear_combination(regresults, R)
regresults |
A list containing two items: |
R |
A vector of length equal to the number of coefficients, representing weights on each of the parameters. |
List with the following values:
estimate
, the point estimate of the linear combination
se
, the standard error of the point estimate
p_value
, the p-value for the null hypothesis that the
linear combination is equal to zero
# test that the returns to one year of education are equal to ten years of age model <- estimatr::lm_robust(earnwk ~ age + educ, data = cps) R <- c(0, -10, 1) # 0 * `intercept` - 10 * `age` + 1 * `education` linear_combination(model, R)
# test that the returns to one year of education are equal to ten years of age model <- estimatr::lm_robust(earnwk ~ age + educ, data = cps) R <- c(0, -10, 1) # 0 * `intercept` - 10 * `age` + 1 * `education` linear_combination(model, R)
Data on married couples in the United States from the 2003 Community Tracking Study (CTS) Household Survey.
married
married
married
A data frame with 4,126 rows and 11 columns:
Age of wife (in years)
Age of husband (in years)
Education of wife (in years)
Education of husband (in years)
Body mass index of wife (bottom-coded at 18, top-coded at 40)
Body mass index of husband (bottom-coded at 18, top-coded at 40)
1 if wife smokes, 0 otherwise
1 if husband smokes, 0 otherwise
1 if wife employed, 0 otherwise
1 if husband employed, 0 otherwise
Annual family income (in dollars, top-coded at $150,000)
https://www.icpsr.umich.edu/web/HMCA/studies/4216
Data on performance in a graduate econometrics course, with GRE test information and domestic/international status available.
metricsgrades
metricsgrades
metricsgrades
A data frame with 68 rows and 4 columns:
Score on GRE quantitative test (out of 170)
Score on GRE verbal test (out of 170)
1 if domestic student, 0 if international student
Overall composite course grade (out of 100 points)
Data on mutual funds categorized as "Large Blend Equity" funds by Morningstar, limited to funds in existence for more than 10 years. Data captured 2/28/2023.
mutualfunds
mutualfunds
mutualfunds
A data frame with 208 rows and 11 columns:
Name of mutual fund
Age of fund (in years)
Expense ratio (net)
Assets under management (in millions of dollars)
Minimum investment level (in dollars)
Y if fund has a load (sales charge or fee), N if not
Tenure of current fund manager (in years)
One-year annualized return
Three-year annualized return
Five-year annualized return
Ten-year annualized return
Data on all game results for the 2020 Premier League soccer season. The Premier League consists of 20 teams. Each team plays every other team twice (home and away) during the season, so there are a total of 38 rounds in the season and 380 total games.
premier
premier
premier
A data frame with 380 rows and 5 columns:
Round (values 1 to 38)
Home team
Away team
Number of goals by the home team
Number of goals by the away team
https://en.wikipedia.org/wiki/2020%E2%80%9321_Premier_League
Data on responses to hypothetical resumes that were created for an experimental study, based upon "Ban the Box, Criminal Records, and Racial Discrimination: A Field Experiment" by Amanda Agan and Sonja Starr, 2018, Quarterly Journal of Economics, 133: 191-235. This dataset considers only the subsample from before the ban-the-box initiative.
resume
resume
resume
A data frame with 7,332 rows and 7 columns:
1 if applicant has criminal record, 0 otherwise
1 if applicant has committed drug crime, 0 otherwise
1 if applicant has committed property crime, 0 otherwise
1 if applicant has GED, 0 otherwise
1 if applicant has a gap in employment, 0 otherwise
1 if applicant is black, 0 otherwise
1 if applicant received positive response, 0 otherwise
These functions calculate the asymptotic standard errors of
common statistical estimates. se_meanx
calculates the
standard error of the mean, se_sx
calculates the standard
error of the population standard deviation estimate, and
se_rxy
calculate the standard error of the correlation
estimate between two vectors.
se_meanx(x, na.rm = FALSE) se_rxy(x, y, na.rm = FALSE) se_sx(x, na.rm = FALSE)
se_meanx(x, na.rm = FALSE) se_rxy(x, y, na.rm = FALSE) se_sx(x, na.rm = FALSE)
x |
A numeric vector, representing a sample from a population |
na.rm |
A boolean, whether or not to remove any |
y |
A numeric vector, representing a sample of a different variable |
A number representing the asymptotic standard error of the particular estimate
# calculate the mean and se of the mean of wage in the cps data paste( "The average wage is", mean(cps$wagehr, na.rm = TRUE), "with a margin of error of", se_meanx(cps$wagehr, na.rm = TRUE) )
# calculate the mean and se of the mean of wage in the cps data paste( "The average wage is", mean(cps$wagehr, na.rm = TRUE), "with a margin of error of", se_meanx(cps$wagehr, na.rm = TRUE) )
Data on monthly returns for S&P 500 companies between Jan 1991 and Apr 2021
sp500
sp500
sp500
A data frame with 364 rows and 268 columns:
Date, as a string, indicating the endpoint of the month
Monthly return for the S&P 500 index
Monthly company returns, where variable name is the company stock ticker symbol
Data on the length of worker contract strikes within U.S. manufacturing for the period 1968-1976, based upon "The Duration of Contract strikes in U.S. Manufacturing" by John Kennan, 1985, Journal of Econometrics, 28: 5-28.
strikes
strikes
strikes
A data frame with 566 rows and 1 column:
Strike duration (in weeks)
https://cameron.econ.ucdavis.edu/mmabook/mmadata.html
test_linear_restrictions
takes a set of regression results and
tests multiple linear restrictions simultaneously.
test_linear_restrictions(regresults, R, c = default_test(R))
test_linear_restrictions(regresults, R, c = default_test(R))
regresults |
A list containing two items: |
R |
A matrix of linear restrictions. Each row of |
c |
A vector of constants, equal to the number of rows in |
A list with the following items:
W: The Wald (chi-square) statistic
p_value: The p-value of the test
# test both that the returns to one year of education are # equal to ten years of age, and that the intercept is zero model <- estimatr::lm_robust(earnwk ~ age + educ, data = cps) R <- matrix(c(0, -10, 1, 1, 0, 0), nrow = 2, byrow = TRUE) test_linear_restrictions(model, R)
# test both that the returns to one year of education are # equal to ten years of age, and that the intercept is zero model <- estimatr::lm_robust(earnwk ~ age + educ, data = cps) R <- matrix(c(0, -10, 1, 1, 0, 0), nrow = 2, byrow = TRUE) test_linear_restrictions(model, R)
These functions help calculate the variance matrix of different
kinds of samples. var_mean_indep
creates an asymptotic
covariance matrix for the sample means of a list of independent
samples. var_prop_indep
creates an asymptotic covariance
matrix for the sample proportions of a list of independent
samples. var_mean_onesample
creates an asymptotic covariance
matrix for the sample means of several variables from the same
sample.
var_mean_indep(x_vectors) var_mean_onesample(df, vars = names(df)) var_prop_indep(pi_hat, nobs)
var_mean_indep(x_vectors) var_mean_onesample(df, vars = names(df)) var_prop_indep(pi_hat, nobs)
x_vectors |
A list of vectors, representing the different independent samples. |
df |
A data.frame object |
vars |
A character vector of variable names in |
pi_hat |
A vector of sample proportions. |
nobs |
The sample size. |
A matrix, representing the asymptotic covariance matrix of the sample means.
# list of independent samples x_vectors <- list( rnorm(1000, mean = 1, sd = 2), rnorm(10, mean = 4, sd = 0.5), rnorm(1000000, mean = 0, sd = 1) ) var_mean_indep(x_vectors) # sample proportions pi_hat <- c(0.1, 0.6, 0.3) nobs <- 1000 var_prop_indep(pi_hat, nobs) # covariance of educ and age in cps dataset var_mean_onesample(cps, c("educ", "age"))
# list of independent samples x_vectors <- list( rnorm(1000, mean = 1, sd = 2), rnorm(10, mean = 4, sd = 0.5), rnorm(1000000, mean = 0, sd = 1) ) var_mean_indep(x_vectors) # sample proportions pi_hat <- c(0.1, 0.6, 0.3) nobs <- 1000 var_prop_indep(pi_hat, nobs) # covariance of educ and age in cps dataset var_mean_onesample(cps, c("educ", "age"))
Given the parameter estimates and their variance-covariance matrix,
wald_test
calculates the Wald test statistic and p-value for
a set of linear constraints on the parameters.
wald_test( gamma_hat, var_gamma_hat, R = diag(length(gamma_hat)), c = default_test(R) )
wald_test( gamma_hat, var_gamma_hat, R = diag(length(gamma_hat)), c = default_test(R) )
gamma_hat |
L x 1 vector of parameter estimates |
var_gamma_hat |
L x L variance-covariance matrix of parameter estimates |
R |
Q x L matrix of linear constraints to be tested. Defaults to identity matrix of size L |
c |
Q x 1 vector of test values for the linear constraints. Defaults to a vector of zeros of length Q to test that all the contrasts are equal to zero. |
A list with the following elements:
W: Wald test statistic
p_value: p-value for the Wald test ( distribution)
# test that union workers earn the same as non-union workers cps$union <- as.numeric(cps$unionstatus == "Union") model <- lm(earnwk ~ union, data = cps) gamma_hat <- coef(model) var_gamma_hat <- vcov(model) wald_test(gamma_hat, var_gamma_hat, R = c(0, 1)) # test that non-union workers make 900/week # *and* union workers make 1000/week wald_test( gamma_hat, var_gamma_hat, R = matrix(c(0, 1, 1, 1), nrow = 2), c = c(900, 1000) )
# test that union workers earn the same as non-union workers cps$union <- as.numeric(cps$unionstatus == "Union") model <- lm(earnwk ~ union, data = cps) gamma_hat <- coef(model) var_gamma_hat <- vcov(model) wald_test(gamma_hat, var_gamma_hat, R = c(0, 1)) # test that non-union workers make 900/week # *and* union workers make 1000/week wald_test( gamma_hat, var_gamma_hat, R = matrix(c(0, 1, 1, 1), nrow = 2), c = c(900, 1000) )
Data on the arrival time of website visitors during a specific hour for a hypothetical website.
website
website
website
A data frame with 748 rows and 2 columns:
Arrival time during the hour (in minutes)
Time since last visitor (in minutes)
Data on purchases for an e-mail experiment run by widgets.com
widgets
widgets
widgets
A data frame with 3,000 rows and 4 columns:
1 if customer receives e-mail A, 0 otherwise
1 if customer receives e-mail B, 0 otherwise
1 if customer makes a purchase, 0 otherwise
Total purchase (in dollars)