# delimit ;
* Answers to test 1, Quantitatives Methods in Marketing;
* Opening the database and creating the .log file to register the results.;
use "E:\Teste MQM\test1.dta", clear;
log using "E:\Teste MQM\test1_answers.log", replace;
* First we declare the times series structure and identify the time variable (year);
tsset year;
* Next we construct the variables we need to run the regression;
generate lnsalespc = ln(salespc);
generate lnrprice = ln(rprice);
generate lnastock = ln(astock);
generate lnincpc = ln(incpc);
generate d71 = 0;
replace d71=1 if year >=1971;
* We want now to check whether variable lnrprice is endogenous. We undertale a
Hausman test to assess the potential endogeneity.
fist step: run the regression of the potential endogeneous variable on all
exogeneous variables;
generate lntobpc = ln(tobpc);
regress lnrprice lnastock lnincpc lntobpc d71, vce(robust);
predict e, resid;
* second step: estimate the original regression by including the residuals from
the first step as an additional variable.;
regress lnsalespc lnrprice lnastock lnincpc d71 e, vce(robust);
* Since the coefficient of the residual is statistically significant, we have
evidence that the price variable is endogenous. We should estimate the
demand equation by applying the two-stage least squares method;
ivregress 2sls lnsalespc (lnrprice=lntobpc) lnastock lnincpc d71, vce(robust);
* Since the coefficient of the dummy variable is not significant, we do not have
evidence that the prohibition of cigarette advertinsing has contributed
to a decrease in cigarette consumption;
* Testing the hypothesis that the price-elasticity of demand is unitary;
test lnrprice = -1;
* Since the p-value is higher than 0.05, we cannot reject the null hypothesis
of unitary elasticity (but we reject if we consider a 10% significance
level, since the p-value is below 0.10);
* Finally, we estimate the lingering effects model with variables in level;
arima salespc l.salespc astock d71, ma(1);
scalar m = ln(1-0.85)/ln(_b[l.salespc]);
display m;
* Results suggest that it will take 105 years to attain 85% of the cumulative impact of
advertising on sales! This is absolutely unrealistic. Our model suffers from the
time aggregation bias. We use yearly data to analyze a market where purchases
occur daily.;
log close ;