# delimit ;
* Code for estimating exercise 4: causality between advertising and
sales;
* First, we open the database and create to log file to store our
results;
use "C:\Users\AutoLogon\Desktop\causal2.dta", clear;
log using "C:\Users\AutoLogon\Desktop\exercise4.log", replace;
* We conduct an endogeneity test for teh income variable;
* First step: run the regression of the potential endogenous variable on
the exogenous including the instrument;
regress ypcr adr gnondefr, vce(robust);
predict e, resid;
* Second step: run the original regression by including the residual
of the first step as an additional variable;
regress cgr ypcr adr e, vce(robust);
* Since the coefficient associated to the residual in the second step is
significant, we have evidence on the endogeneity of variable ypcr.
We should estimate the consumption equation by using a instrumental
variable model (in our case, 2SLS);
ivregress 2sls cgr adr (ypcr=gnondefr), vce(robust);
* Our results support the statement that advertising does not have an effect on aggregate consumption, since the coefficient associated to
advertsing is not singificant;
* Now we test the hypothesis that the marginal propensity to consume
is equal to 0.5;
test ypcr=0.5;
* We have a p-value of 0.347, which is higher than 0.10. So, we do not reject the hypothesis that the marginal propensity to consume is equal to
0.5;
* LetÂ´s implement a Granger test to verify whether advertising causes
sales. We will run the regression specified in the exercise (in
practice, you should run regressions with different lag structures to
be sure about the causality);
tsset obsno;
regress cgr l.cgr l2.cgr l.adr l2.adr, vce(robust);
test l.adr = l2.adr=0;
* Since our F-test has a very high p-value (0.823), we do not reject the null. So, we have evidence that advertising does not Granger cause
sales. This means that variations in advertising do not precede
variations in consumption.;
log close;