I want to add a shock on capital stock. I search the forum and find your code of RBC_capitalstock_shock.mod which makes a typical example. I just want to make sure that:

(1) In the notation of the code, you said that “the timing for k in all other equations changes to being contemporaneous” and the the law of motion for capital is written as
exp(k) = exp(-eps_cap)*(exp(invest(-1))+(1-delta)*exp(k(-1)));

So in other equations which include variable “invest”, I sould substitue it by
exp(invest)=exp(k(+1))/exp(-eps_cap(+1))-(1-delta)*exp(k);
and calculate derivative with respect to k(+1). Is this correct ?

(2) In your code, eps_cap is exogenous variable. I wonder if I could use the code as follows:
exp(k) = exp(eps_k)*(exp(invest(-1))+(1-delta)*exp(k(-1)));
and
exp(eps_k) = (1 - rhokUU) * 1 + rhokUU * exp(eps_k(-1)) + e_k;
in which eps_k is endogenous variable and e_k is the exogenous one. Is this correct ?

The bayesian estimation results on the two types of introducing capital shock above are quite different and I have no idea about the reason.

I’m very sorry that I did not make the first question clear.

I know the entrepreneur’s equations without capital shock is as:
…
exp(k) = exp(invest)+(1-delta)*exp(k(-1));
exp(y) = exp(z)*exp(k(-1))^alpha * exp(l)^(1-alpha);
exp(consume)+exp(invest)+ exp(w)*exp(l)+exp(rate(-1))*exp(b(-1))/exp(pi) = exp(y)+ exp(b);
exp(rate) * exp(b)=m * ( exp(qk(+1)) * (1-deltaUU)*exp(k)*exp(pi(+1)) ); %credit constraint
…

While when capital shock came in, the equations become as:
…
exp(k) = exp(e_k)*( exp(invest(-1))+(1-delta)*exp(k(-1)) );
exp(y) = exp(z)exp(k)^alphaexp(l)^(1-alpha);
exp(consume) +exp(invest)+ exp(w)*exp(l)+exp(rate(-1))*exp(b(-1))/exp(pi) = exp(y)+ exp(b);
exp(rate) * exp(b)=m * ( exp(qk(+1)) * (1-deltaUU)*exp(k(+1))*exp(pi(+1)) ); //credit constraint
…

In this case, I feel a little confused about the first-order condition on variable “invest” and “k”.
How should I calculate derivative with respect to invest and k ?

Thanks again for your time, Professor.
Best regards

When taking the derivative with respect to k at time t, how should I deal with k(+1) in the budget constraint and credit constraint ? It seems that I have never encountered this kind of situation before. And sorry if I asked a stupid question.

But capital does not show up in the budget constraint. With respect to the credit constraint: what is the logic here behind the timing, i.e. is the timing correct?

As the notation in your code of RBC_capitalstock_shock.mod says:
“Similarly, the timing for k in all other equations changes to being contemporaneous.”
I thought it means that I should go forward one period for k in other equation, so I changed the k(t) in credit constraint into k(t+1). Did I misunderstand this ?

With respect to variable invest, I thought it could be substituted by
exp(invest)=exp(k(+1))/exp(e_k(+1))-(1-delta) * exp(k);
according to the law of motion for capital
exp(k) = exp(e_k)*(exp(invest(-1))+(1-delta) * exp(k(-1)));
Then there is k(t+1) in the budget constraint. Did I also misunderstand something in this ?

So the timing of k in credit constraint will retain k(t) as it still represents capital stock at the end of time t. Is it correct?

Sorry but I really feel confused about the timing here, and I cannot find this capital shock in any paper. As you said, I should think about the economic logic of the model. I used to treat k(t-1) as the capital stock at the beginning of t and k(t) as which at the end of t. However, when capital shock comes in, the law of motion for capital changes to
exp(k) = exp(e_k)*(exp(invest(-1))+(1-delta) * exp(k(-1))).
k(t) seems not like the meaning I considered before ? While you said I cannot substitute out the investment, how should I calculate derivative with respect to investment in this case ? The equation may become even more complex when investment adjustment cost come in.