Title: | Estimation of Censored AI/QUAI Demand System via Maximum Likelihood Estimation (MLE) |
Type: | Package |
Version: | 1.0.0 |
Description: | Tools for estimating censored Almost Ideal (AI) and Quadratic Almost Ideal (QUAI) demand systems using Maximum Likelihood Estimation (MLE). It includes functions for calculating demand share equations and the truncated log-likelihood function for a system of equations, incorporating demographic variables. The package is designed to handle censored data, where some observations may be zero due to non-purchase of certain goods. Package also contains a procedure to approximate demand elasticities numerically and estimate standard errors via Delta Method. It is particularly useful for applied researchers analyzing household consumption data. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
Depends: | R (≥ 3.5) |
Imports: | Matrix, mnormt, mvtnorm, stats, matrixcalc |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-03-18 12:14:49 UTC; Noe.Nava |
Author: | Noé J Nava [aut, cre] |
Maintainer: | Noé J Nava <noejnava2@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-03-18 13:00:09 UTC |
National Survey of Household Income and Expenditures (ENIGH)
Description
MexicanHH_foodConsumption is a 10 percent sample of the data described in Beckman et al. (2024)'s Land Competition and Welfare Effects from Mexico's Proposal to Ban Genetically Modified Corn. An overview of the data construction and assessment is further discussed in the study.
Usage
MexicanHH_foodConsumption
Format
## 'MexicanHH_foodConsumption' A data frame with 8,777 rows and 17 columns:
- s1
Share of tortilla consumption by household.
- s2
Share of cereal consumption by household.
- s3
Share of meat consumption by household.
- s4
Share of dairy consumption by household.
- s5
Share of fruits and vegetables consumption by household.
- s6
Share of other consumption by household.
- lnp1
Logged price of tortilla.
- lnp2
Logged price of cereal.
- lnp3
Logged price of meat.
- lnp4
Logged price of dairy.
- lnp5
Logged price of fruits and vegetables.
- lnp6
Logged price of other.
- lnw
Logged food expenditure by household .
- age
Logged age of head of household.
- size
Inverse (1/x) of size of household.
- sex
Sex (female == 1) of head of household.
- educ
Educational attaintment of head of household.
' @source <https://en.www.inegi.org.mx/programas/enigh/nc/2022/>
Calculate the demand share equations of a AI or QUAI demand system, including demographic variable.
Description
Calculate the demand share equations of a AI or QUAI demand system, including demographic variable.
Usage
aidsCalculate(
Prices = matrix(),
Budget = matrix(),
ShareNames = NULL,
Demographics = matrix(),
DemographicNames = NULL,
Params = matrix(),
quaids = FALSE
)
Arguments
Prices |
A matrix of logged prices with (nxm) dimensions where n is the number of observations and m the number of shares. |
Budget |
A matrix of logged total expenditure/budget with (nx1) dimensions where n is the number of observations. |
ShareNames |
A vector of strings containing the share names with (mx1) dimensions where m is the number of shares. |
Demographics |
A matrix of demographic variables with (nxt) dimensions where n is the number of observations and t the number of demographic variables. |
DemographicNames |
A vector of strings containing the demographic names with (tx1) dimensions where t is the number of demographic variables. |
Params |
A vector containing the parameters alpha, beta, gamma, and theta and lambda if elected. |
quaids |
Logical. Should quadratic form be used instead? |
Value
A matrix of estimated shares with (nxm) dimensions where n is the number of observations and m the number of shares.
Examples
## Not run:
testing_data <- censoredAIDS::MexicanHH_foodConsumption
# Organizing the data for comfort
s1 <- testing_data$s1
s2 <- testing_data$s2
s3 <- testing_data$s3
s4 <- testing_data$s4
s5 <- testing_data$s5
s6 <- testing_data$s6
lnp1 <- testing_data$lnp1
lnp2 <- testing_data$lnp2
lnp3 <- testing_data$lnp3
lnp4 <- testing_data$lnp4
lnp5 <- testing_data$lnp5
lnp6 <- testing_data$lnp6
age <- testing_data$age
size <- testing_data$size
sex <- testing_data$sex
educ <- testing_data$educ
# Alpha
b0 <- rep(0, 5)
# Beta
b0 <- c(b0, rep(0.003, 5))
# Gamma
b0 <- c(b0,0.01,0,0.01,0,0, 0.01,0,0,0,0.01,0,0,0,0,0.01)
# Demos
b0 <- c(b0,rep(0.002, 20))
# Sigma
b0 <- c(b0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
li1 <- censoredaidsLoglike(
Params = b0,
Shares = matrix(c(s1, s2, s3, s4, s5, s6), ncol = 6),
Prices = matrix(c(lnp1, lnp2, lnp3, lnp4, lnp5, lnp6), ncol = 6),
Budget = matrix(testing_data$lnw),
Demographics = matrix(c(age, size, educ, sex), ncol = 4),
quaids = FALSE
)
## End(Not run)
Numerical approximation to censored AI or QUAI demand system elasticities, including demographic variable.
Description
Numerical approximation to censored AI or QUAI demand system elasticities, including demographic variable.
Usage
censoredElasticity(
Prices = matrix(),
Budget = matrix(),
ShareNames = NULL,
Demographics = matrix(),
DemographicNames = NULL,
Params = matrix(),
quaids = FALSE,
vcov = matrix(),
func,
...
)
Arguments
Prices |
A matrix of logged prices with (nxm) dimensions where n is the number of observations and m the number of shares. |
Budget |
A matrix of logged total expenditure/budget with (nx1) dimensions where n is the number of observations. |
ShareNames |
A vector of strings containing the share names with (mx1) dimensions where m is the number of shares. |
Demographics |
A matrix of demographic variables with (nxt) dimensions where n is the number of observations and t the number of demographic variables. |
DemographicNames |
A vector of strings containing the demographic names with (tx1) dimensions where t is the number of demographic variables. |
Params |
A vector containing the parameters alpha, beta, gamma, and theta and lambda if elected. |
quaids |
Logical. Should quadratic form be used instead? |
vcov |
A variance-covariance matrix of the parameters. Must be positive semi-definite and symmetric. |
func |
A function to be applied to the data at which point estimate elasticities are being evaluated. |
... |
Additional arguments to be passed to func. |
Value
A list containing a matrix of price and income elasticities, a matrix with their respective standard errors approximated using the delta method, and a matrix of expected shares that can serve to run further post-estimation analyses.
Examples
## Not run:
testing_data <- censoredAIDS::MexicanHH_foodConsumption
# Organizing the data for comfort
s1 <- testing_data$s1
s2 <- testing_data$s2
s3 <- testing_data$s3
s4 <- testing_data$s4
s5 <- testing_data$s5
s6 <- testing_data$s6
lnp1 <- testing_data$lnp1
lnp2 <- testing_data$lnp2
lnp3 <- testing_data$lnp3
lnp4 <- testing_data$lnp4
lnp5 <- testing_data$lnp5
lnp6 <- testing_data$lnp6
age <- testing_data$age
size <- testing_data$size
sex <- testing_data$sex
educ <- testing_data$educ
# Alpha
b0 <- rep(0, 5)
# Beta
b0 <- c(b0, rep(0.003, 5))
# Gamma
b0 <- c(b0,0.01,0,0.01,0,0, 0.01,0,0,0,0.01,0,0,0,0,0.01)
# Demos
b0 <- c(b0,rep(0.002, 20))
# Sigma
b0 <- c(b0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
vcov <- matrix(0, nrow = length(b0), ncol = length(b0))
vcov[upper.tri(vcov, diag = TRUE)] <- runif(.5*length(b0)*(1+length(b0)))
vcov <- t(vcov) %*% vcov
list_etas <- censoredElasticity(
Params = b0,
Shares = matrix(c(s1, s2, s3, s4, s5, s6), ncol = 6),
Prices = matrix(c(lnp1, lnp2, lnp3, lnp4, lnp5, lnp6), ncol = 6),
Budget = matrix(testing_data$lnw),
Demographics = matrix(c(age, size, educ, sex), ncol = 4),
quaids = FALSE,
func = mean,
na.rm = TRUE,
vcov = vcov
)
## End(Not run)
Calculates the truncated (censored) log-likehood function of a share system of equations of a AI or QUAI demand system.
Description
Calculates the truncated (censored) log-likehood function of a share system of equations of a AI or QUAI demand system.
Usage
censoredaidsLoglike(
Shares = matrix(),
Prices = matrix(),
Budget = matrix(),
ShareNames = NULL,
Demographics = matrix(),
DemographicNames = NULL,
Params = matrix(),
quaids = FALSE
)
Arguments
Shares |
A matrix of shares with (nxm) dimensions where n is the number of observations and m the number of shares. |
Prices |
A matrix of logged prices with (nxm) dimensions where n is the number of observations and m the number of shares. |
Budget |
A matrix of logged total expenditure/budget with (nx1) dimensions where n is the number of observations. |
ShareNames |
A vector of strings containing the share names with (mx1) dimensions where m is the number of shares. |
Demographics |
A matrix of demographic variables with (nxt) dimensions where n is the number of observations and t the number of demographic variables. |
DemographicNames |
A vector of strings containing the demographic names with (tx1) dimensions where t is the number of demographic variables. |
Params |
A vector containing the parameters alpha, beta, gamma, and theta and lambda if elected. |
quaids |
Logical. Should quadratic form be used instead? |
Value
A numeric vector for individual loglikehood contributions with dimensions (nx1) where n is the number of observations.
Examples
## Not run:
testing_data <- censoredAIDS::MexicanHH_foodConsumption
# Organizing the data for comfort
s1 <- testing_data$s1
s2 <- testing_data$s2
s3 <- testing_data$s3
s4 <- testing_data$s4
s5 <- testing_data$s5
s6 <- testing_data$s6
lnp1 <- testing_data$lnp1
lnp2 <- testing_data$lnp2
lnp3 <- testing_data$lnp3
lnp4 <- testing_data$lnp4
lnp5 <- testing_data$lnp5
lnp6 <- testing_data$lnp6
age <- testing_data$age
size <- testing_data$size
sex <- testing_data$sex
educ <- testing_data$educ
# Alpha
b0 <- rep(0, 5)
# Beta
b0 <- c(b0, rep(0.003, 5))
# Gamma
b0 <- c(b0,0.01,0,0.01,0,0, 0.01,0,0,0,0.01,0,0,0,0,0.01)
# Demos
b0 <- c(b0,rep(0.002, 20))
# Sigma
b0 <- c(b0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
f <- censoredaidsLoglike(
Params = b0,
Shares = matrix(c(s1, s2, s3, s4, s5, s6), ncol = 6),
Prices = matrix(c(lnp1, lnp2, lnp3, lnp4, lnp5, lnp6), ncol = 6),
Budget = matrix(testing_data$lnw),
Demographics = matrix(c(age, size, educ, sex), ncol = 4),
quaids = FALSE
)
## End(Not run)
Calculate the demand share equations of a AI or QUAI demand system, including demographic variable, using point estimates (e.g., mean, median, percentiles).
Description
Calculate the demand share equations of a AI or QUAI demand system, including demographic variable, using point estimates (e.g., mean, median, percentiles).
Usage
muaidsCalculate(
muPrices = numeric(),
muBudget = numeric(),
muDemographics = numeric(),
Params = matrix(),
quaids = FALSE,
m = numeric(),
t = numeric(),
dems = FALSE
)
Arguments
muPrices |
A matrix of logged muPrices with (1xm) dimensions where n is the number of observations and m the number of shares. |
muBudget |
A matrix of logged total expenditure/muBudget with (1x1) dimensions where n is the number of observations. |
muDemographics |
A matrix of demographic variables with (1xt) dimensions where n is the number of observations and t the number of demographic variables. |
Params |
A vector containing the parameters alpha, beta, gamma, and theta and lambda if elected. |
quaids |
Logical. Should quadratic form be used instead? |
m |
Number of shares. |
t |
Number of demographic variables. |
dems |
Bolean. Should demographic variables be included? |
Value
A matrix of estimated shares with (1xm) dimensions where n is the number of observations and m the number of shares.