Optimization of Households' utility in " Rule-of-Thumb Consumers and the Design of Interest Rate Rules " (Gali et al., 2004) I can't figure out how the calculation of first order conditions was carried out.





I can't figure out where the stochastic discount factor came from.
In this case, the stochastic discount factor appears in equation (7), the intertemporal optimization equation. You can derive (7) by taking the first order conditions of the Lagrangean function with respect to consumption, and then investment (or capital, K_t+1, if you want to substitute out the capital accumulation equation). You then combine these two optimality conditions to yield (7).

The stochastic discount factor, then, is just the ratio of marginal utilities of consumption in period t+1 and t. The ratio of prices appears in the stochastic discount factor because this is a nominal model, and you need to discount future nominal payoffs by inflation between time t and t+1.