utility maximization with nested Cobb–Douglas–CES preferences I'm trying to understand the following paper: Hsieh &amp; Ossa: A global view of productivity growth in China (2016). The pdf can be found here: https://faculty.chicagobooth.edu/chang-tai.hsieh/research/hsieh_ossa_jie.pdf

I struggle to understand the utility maximization problem right at the beginning of the paper. Can someone show me how to maximize the following utility with respect to $x_{ijs}$:

$U_j=\prod_s^S\left(\sum_i^N \int_0^{M_is^e}x_{ijs}(\nu_{is})^{\frac{\sigma_s-1}{\sigma_s}}d\nu_{is} \right)^{\frac{\sigma_s}{\sigma_s-1}\mu_{js}}$

The end result is:

$x_{ijs}=\frac{p_{ijs}^{-\sigma_s}}{P_{js}^{1-\sigma_s}}\mu_{js}E_j$

where $P_{js}=\left(\sum_i^N M_{is}^ep_{ijs}^{1-\sigma_s}\right)^\frac{1}{1-\sigma_s}$

$N$: number of countries 

$S$: number of industries 

$M_{is}^e$: number of entrants in industry s of country i

$x_{ijs}$: quantity of an industry s variety from country i consumed in country j

$\mu_{js}$: fraction of country j income spent on industry s varieties

$\sigma_s&gt;1$: elasticity of substitution between industry s varieties

$p_{ijs}$: price of an industry s variety from country i in country j

$P_{js}$: ideal price index in industry s of country j

$E_j$: total expenditure in country j
Take the following utility function:
$$
\prod_{s \in S} \left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} \right)^{\frac{\sigma_s}{\sigma_s-1}\mu_{s}}
$$
Which is a CES nested in a Cobb-Douglas.
Consider the sub-utility function:
$$
Q_{s} = \left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s - 1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s - 1}}.
$$
Then we can re-write the utility function succinctly as:
$$
U = \prod_{s \in S} Q_s^{\mu_s}
$$
To solve the utility maximisation problem. Notice that $U$ is separable in the subgroups. As such, we can solve the problem using two stage budgeting.

In the first step, we can determine the optimal allocation within each subgroup $s$ by maximize the sub-utility functions $Q_s$ given the total expenditure $E_s$ given on each subgroup $s$.
In the second step, we determine the optimal allocation of income across each subgroup $s$.

For Step 1, we solve the following problem:
$$
\max\left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s - 1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s - 1}} \text{subject to } \sum_{i \in N} p_{i,s} x_{i,s} = E_s.
$$
This is a CES utility function. The first order condition gives:
$$
Q_s \frac{x_{i,s}^{-\frac{1}{\sigma_s}}}{\sum_{w \in N} x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}} = \lambda p_{i,s}.
$$
Then:
$$
x_{i,s} = \lambda^{-\sigma_s} p_{i,s}^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-1\sigma_s}
$$
Multiplying by $p_{i,s}$ and adding over all $i \in N$ gives:
$$
\begin{align*}
E_s = \sum_{i \in N} p_{i,s} x_{i,s} &amp;= \lambda^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-\sigma_s} \sum_{i \in N} p_{i,s}^{1 - \sigma_s}\\
&amp;= \lambda^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-\sigma_s} P_s^{1 - \sigma_s}
\end{align*}
$$
Where $E_{s} = \sum_{i\in N} p_{i,s} x_{i,s}$ and $P_{s}^{1- \sigma_s} = \sum_{i \in N} p_{i,s}^{1- \sigma_s}$.
Then:
$$
x_{i,s} = E_{s} \frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1-\sigma_s}} \tag{1}
$$
Let's compute the value of $Q_s$:
$$
\begin{align*}
&amp;x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} = E_{s}^{\frac{\sigma_s-1}{\sigma_s}} \left(\frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1 -\sigma_s}}\right)^{\frac{\sigma_s-1}{ \sigma_s}},\\
\to &amp;\sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}}= E_{j,s}^{\frac{\sigma_s-1}{\sigma_s}} \left(\frac{1}{P_{s}^{1- \sigma_s}}\right)^{\frac{\sigma_s-1}{\sigma_s}} \sum_{i \in N} p_{i,s}^{(1-\sigma_s)},\\
\to&amp; \sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} = E_{s}^{\frac{\sigma_s-1}{\sigma_s}} P_{s}^{\frac{1 - \sigma_s}{\sigma_s}}\\
\to &amp; \left(\sum_i x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s-1}} = E_{s} P_{s}^{-1}\\
\to&amp; P_{s} Q_s = E_{s}.
\end{align*}
$$
This shows that the price index $P_s$ and the quantity index $Q_s$ are exact price and quanty indices for this subgroup (as is expected as we were maximising a CES utility function).
Let's now go to step 2. Notice that the budget constraint can be rewritten as:
$$
E = \sum_{s} E_s = \sum_s P_s Q_s.
$$
We want to determine $E_s$ to maximize:
$$
U = \prod_{j \in S} Q_{s}^{\mu_{j,s}} \text{ s.t. } \sum_s P_{s} Q_{s} = E.
$$
This is a simple Cobb-Douglas utility function. As such, we know that expenditure shares are proportional to income:
$$
P_s Q_s = E_s = \frac{\mu_s}{\sum_w \mu_w} E
$$
Finally, substitute this into the equation $(1)$:
$$
x_{i,s} = \frac{\mu_{s}}{\sum_w \mu_w} E \frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1- \sigma_s}}
$$