<p>Without random term, this exercise is closer to nonlinear equations solving than to econometrics. If the true relationship between income and apples is:
<span class="math-container">$$ \log( y_{nt} ) = \gamma \log( x_{nt}),$$</span>
but instead of observing <span class="math-container">${x_{nt}}$</span>, the econometrician actually observes
<span class="math-container">$$x^*_{nt}= \delta_n (x_{nt} + u_t), $$</span>
then, using observed variables, we have
<span class="math-container">$$ \log( y_{nt} ) = \gamma \log( \beta_{0t} +  \beta_{1n} x^*_{nt} )$$</span>
with
<span class="math-container">$$ \beta_{0t} := - u_t $$</span>
<span class="math-container">$$ \beta_{1n} := \frac{1}{\delta_n}. $$</span></p>
<p>If there are more observations than parameters: <span class="math-container">$NT&gt;N+T+1,$</span> which is the case in your example, all the parameters can be computed exactly, using a nonlinear solver minimizing (for instance):
<span class="math-container">$$ \left( \log( y ) - f(\gamma,\{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N; x^* \right)^T\left( \log( y ) - f(\gamma,\{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N; x^* \right) $$</span>
in <span class="math-container">$(\gamma, \{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N ).$</span></p>
<p>Note that it a bit is strange that apples (consumption ?) determine income, usually it is the other way round. With this specification,  individuals have an incentive to buy apples in order to increase their income,... indefinitely if apples are cheap enough: endogeneity occurs, but it is not a problem here, as there is no random term.</p>
<p>Here is a R-code illustrating the claim:</p>
<pre><code># -------------------------
library(optimx)

dat_dum_T = rbind(1,1) %x% matrix( c( rep( 0, 8 ), rep( 1, 21 )), ncol=1 ) 
dat_dum_N = diag(1,nrow=2) %x% rep( 1, 29 )

colnames( dat_dum_N ) &lt;- c( paste0(&quot;dum_N_&quot;, 1:2 ) )

#
# This function computes the sum of squared residuals for different 
# parameter values
#
SSR_f = function( param, Data=DT ){
  
  gamma = param[1]
  par_dum_N = matrix( param[2:3], ncol=1 )
  par_dum_T = param[4]

  rownames( par_dum_N ) = paste0( &quot;beta_N_&quot;, seq(1:2))

  ln_y = Data[,&quot;ln_Y&quot;]
  x_obs = Data[,&quot;observed&quot;]

  dum_N = par_dum_N[1]*dat_dum_N[,1] + par_dum_N[2]*dat_dum_N[,2] 
  dum_T = par_dum_T*dat_dum_T
    
  # The observed and true x are related by 
  # x_nt = x_obs_nt/dum_n + par_dum_t

  SSR = as.numeric( sum( ( ln_y - gamma*( log( x_obs/dum_N - dum_T ) ) )^2 ) )
  return( SSR )
}

true_val = c( 0.3, 1, 0.5, 0.3 )
SSR_f( true_val, DT )

par_0 = c( 0.5, 0.5, 1, 0 )
names(par_0) = c( &quot;gamma&quot;,&quot;dum_N_1&quot;,&quot;dum_N_2&quot;, &quot;dum_T&quot; )

# check if starting values are admissible (and cause no numerical problem)
SSR_f( par_0, DT )

# The nonlinear numerical minimization procedure
optimx( par=par_0, fn=SSR_f, method=&quot;Nelder-Mead&quot;, control = list( trace=4, maxit=1000 ) )
</code></pre>

CC BY-SA 4.0
2022-02-10T17:20:52.783Z
Hi @Bertrand, thanks for replying. I did not think of doing it this way, and tbh I'm not too familiar with nonlinear solvers, but what this is saying is that if I try to minimize the distance between observed and predicted log income (under a specific form for the predicted log income), then I can estimate the parameters. Why did you say that this would not work if there was an error term? Doesn't the solver compute (with certain confidence intervals) the same parameters, even if there is an error term?
Daycent
CC BY-SA 4.0
2022-02-10T17:21:07.097Z
Also, what if I relax the econometrician's understanding of the form of the relationship? 
e.g. $$x_{nt}^{*} = \delta_na_tx_{nt}+u_t+b_n+\epsilon_{nt}$$ OR $$x_{nt}^{*} = \delta_n(a_tx_{nt}+u_t+b_n)+\epsilon_{nt}$$ 
This would still work, right? I would just use the nonlinear solver for each functional form of the relationship that I suspect, and then compare estimates given different functional forms, correct? As long as $NT>2N+2T+1$?
Daycent
CC BY-SA 4.0
2022-02-10T18:46:22.713Z
@Daycent: I wanted to say that if you set $\varepsilon_{nt}=0$ in $$ \log( y_{nt} ) = \gamma \log( x_{nt})+\varepsilon_{nt},$$ then the (nonlinear) sum of squared residuals will be exactly zero in your case, and the solution will be exact and not random.  I should add a R code in my answer... to illustrate the claim. When $\varepsilon_{nt}$ is there, it is better not trying to estimate the "incidental" parameters but rather parameters of their distribution. See Wooldridge textbook for details. In your example $N=2$ and $T=29$ the sample is too small to obtain "good" parameter estimates.
Bertrand
CC BY-SA 4.0
2022-02-09T20:19:42.360Z
2022-02-14T20:53:03.520Z
2022-02-14T20:53:03.520Z
Bertrand
<p>From Nick Huntington-Klein, <em>The Effect</em>:</p>
<blockquote>
<p>Fixed effects is a method of controlling for all variables, whether
they’re observed or not, as long as they stay constant within some
larger category. How can we do that? Simple! We just control for the
larger category, and in doing so we control for everything that is
constant within that category.11 If you prefer, we’re controlling for
a variable higher up on the hierarchy of our hierarchical data.</p>
<p>What does it mean for a variable to be “constant within some larger
category?” For example, let’s say we’re looking at the effect of rural
towns getting electricity on their productivity. An obvious back door
is geography. Rural towns up in the mountainous hillside will be more
difficult to electrify, and also might be different in their
productivity for other reasons.</p>
</blockquote>
<p>Suppose that I have a dataset where I have fixed effects that come in both multiplicatively and additively.</p>
<p>e.g. Let's say I'm trying to see the relationship between apples consumed and income. I observe household apples, and I suspect that Bob MIS-reports his consumed apples. The value is always 0.5x true apples. While, on the other hand, Alice's survey data is always accurate with no measurement error. This is multiplicatively constant across the category &quot;individual&quot;.</p>
<p>In addition to this, for the years after 2000, a new survey came out, and I suspect that now all of the household survey apples measures had 0.3 added to each measure. This is additively constant across the category &quot;year&quot;.</p>
<p>If I knew these numbers (+0.3 and 0.5x), then I could subtract them off my data. But, let's say I <strong>don't</strong> know these numbers, and only have a suspicion that some of my data has both <em>multiplicative</em> and <em>additive</em> effects that potentially confound any estimation.</p>
<p>Moreover, let's say that the true relationship between income and apples consumed is given by</p>
<p><span class="math-container">$$\log(\text{income}) = 0.3 \log(\text{apples})$$</span></p>
<p>How do I estimate the true relationship, given I observe <span class="math-container">$$\text{observed apples} = \left(\text{apples} + 0.3 * \text{I}(\text{year}&gt;=2000)\right)*\begin{cases}0.5 &amp; ID = Bob\\1 &amp; ID \ne Bob\end{cases}$$</span></p>
<p>If the effect was multiplicative, then I could just use a typical fixed effect regression.
If the fixed effect was additive, then I could just de-mean the observations and run the regression that way. But since this has both, if I use a log-log model with fixed effects, then the additively constant effect is no longer constant within time.</p>
<p>Here is the code I've used. Thanks a bunch in advance!</p>
<pre><code>library(data.table)
library(fixest)
library(modelsummary)

DT &lt;- CJ(ID = c(&quot;Bob&quot;, &quot;Alice&quot;),
         year = 1992:2020)

# make observations
DT[, truth := runif(nrow(DT))]

# create fixed effects
DT[, ID_FE := ifelse(ID == &quot;Bob&quot;, 0.5, 1)]
DT[, year_FE := ifelse(year &gt;= 2000, 0.3, 0)]

# create observed variable:
DT[, observed := (truth + year_FE) * ID_FE]

# create additive means
DT[, ID_mean := mean(observed), by = .(ID)]
DT[, year_mean := mean(observed), by = .(year)]

# create multiplicative means
DT[, ID_log_mean := mean(log(observed)), by = .(ID)]
DT[, year_log_mean := mean(log(observed)), by = .(year)]
DT[, ln_observed := log(observed)]

# create differences for manual FE estimation
DT[, diff_ln_observed := ln_observed - ID_log_mean - year_log_mean]
DT[, diff_observed := observed - ID_mean - year_mean]

# get actual Y
DT[, Y := truth ^ 0.3]
DT[, ln_Y := log(Y)]

# run regression
true_relationship &lt;- lm(ln_Y~log(truth),data = DT)
m1 &lt;- lm(ln_Y ~ diff_ln_observed, data = DT)
twfe &lt;-feols(ln_Y ~ log(observed) |as.factor(ID) + as.factor(year),data = DT)
msummary(list(true_relationship, m1, twfe))
</code></pre>

CC BY-SA 4.0
2022-02-11T19:50:55.773Z
In your code, the line: 
DT[, year_FE := ifelse(year >= 2000, 0.3, 1)] 
does not correspond to your equation:
 $$0.3 * \text{I}(\text{year}>=2000)$$
unless you change it to: 
 $$ 1 - 0.7 * \text{I}(\text{year}>=2000)$$
Bertrand
CC BY-SA 4.0
2022-02-14T17:04:48.353Z
My bad. Changed the code to `DT[, year_FE := ifelse(year >= 2000, 0.3, 0)]`
Daycent
<econometrics><applied-econometrics><statistics>
How to deal with multiplicatively constant and additively constant fixed effects?
Daycent
# How to deal with multiplicatively constant and additively constant fixed effects?

(Asked by: username_0 on 2022-02-07)

From Nick Huntington-Klein, The Effect:

Fixed effects is a method of controlling for all variables, whether
they’re observed or not, as long as they stay constant within some
larger category. How can we do that? Simple! We just control for the
larger category, and in doing so we control for everything that is
constant within that category.11 If you prefer, we’re controlling for
a variable higher up on the hierarchy of our hierarchical data.
What does it mean for a variable to be “constant within some larger
category?” For example, let’s say we’re looking at the effect of rural
towns getting electricity on their productivity. An obvious back door
is geography. Rural towns up in the mountainous hillside will be more
difficult to electrify, and also might be different in their
productivity for other reasons.

Suppose that I have a dataset where I have fixed effects that come in both multiplicatively and additively.
e.g. Let's say I'm trying to see the relationship between apples consumed and income. I observe household apples, and I suspect that Bob MIS-reports his consumed apples. The value is always 0.5x true apples. While, on the other hand, Alice's survey data is always accurate with no measurement error. This is multiplicatively constant across the category "individual".
In addition to this, for the years after 2000, a new survey came out, and I suspect that now all of the household survey apples measures had 0.3 added to each measure. This is additively constant across the category "year".
If I knew these numbers (+0.3 and 0.5x), then I could subtract them off my data. But, let's say I don't know these numbers, and only have a suspicion that some of my data has both multiplicative and additive effects that potentially confound any estimation.
Moreover, let's say that the true relationship between income and apples consumed is given by
$$\log(\text{income}) = 0.3 \log(\text{apples})$$
How do I estimate the true relationship, given I observe $$\text{observed apples} = \left(\text{apples} + 0.3 * \text{I}(\text{year}>=2000)\right)*\begin{cases}0.5 & ID = Bob\\1 & ID \ne Bob\end{cases}$$
If the effect was multiplicative, then I could just use a typical fixed effect regression.
If the fixed effect was additive, then I could just de-mean the observations and run the regression that way. But since this has both, if I use a log-log model with fixed effects, then the additively constant effect is no longer constant within time.
Here is the code I've used. Thanks a bunch in advance!
library(data.table)
library(fixest)
library(modelsummary)

DT <- CJ(ID = c("Bob", "Alice"),
         year = 1992:2020)

# make observations
DT[, truth := runif(nrow(DT))]

# create fixed effects
DT[, ID_FE := ifelse(ID == "Bob", 0.5, 1)]
DT[, year_FE := ifelse(year >= 2000, 0.3, 0)]

# create observed variable:
DT[, observed := (truth + year_FE) * ID_FE]

# create additive means
DT[, ID_mean := mean(observed), by = .(ID)]
DT[, year_mean := mean(observed), by = .(year)]

# create multiplicative means
DT[, ID_log_mean := mean(log(observed)), by = .(ID)]
DT[, year_log_mean := mean(log(observed)), by = .(year)]
DT[, ln_observed := log(observed)]

# create differences for manual FE estimation
DT[, diff_ln_observed := ln_observed - ID_log_mean - year_log_mean]
DT[, diff_observed := observed - ID_mean - year_mean]

# get actual Y
DT[, Y := truth ^ 0.3]
DT[, ln_Y := log(Y)]

# run regression
true_relationship <- lm(ln_Y~log(truth),data = DT)
m1 <- lm(ln_Y ~ diff_ln_observed, data = DT)
twfe <-feols(ln_Y ~ log(observed) |as.factor(ID) + as.factor(year),data = DT)
msummary(list(true_relationship, m1, twfe))

**Tags:** econometrics, applied-econometrics, statistics

> **Comments:**
> **username_1**: In your code, the line:  DT[, year_FE := ifelse(year >= 2000, 0.3, 1)]  does not correspond to your equation:  $$0.3 * \text{I}(\text{year}>=2000)$$ unless you change it to:   $$ 1 - 0.7 * \text{I}(\text{year}>=2000)$$  
> **username_0**: My bad. Changed the code to `DT[, year_FE := ifelse(year >= 2000, 0.3, 0)]`  

---

## 1 answers

### Answer by username_1 on 2022-02-09. Score: 3 | Accepted answer

Without random term, this exercise is closer to nonlinear equations solving than to econometrics. If the true relationship between income and apples is:
$$ \log( y_{nt} ) = \gamma \log( x_{nt}),$$
but instead of observing ${x_{nt}}$, the econometrician actually observes
$$x^*_{nt}= \delta_n (x_{nt} + u_t), $$
then, using observed variables, we have
$$ \log( y_{nt} ) = \gamma \log( \beta_{0t} +  \beta_{1n} x^*_{nt} )$$
with
$$ \beta_{0t} := - u_t $$
$$ \beta_{1n} := \frac{1}{\delta_n}. $$
If there are more observations than parameters: $NT>N+T+1,$ which is the case in your example, all the parameters can be computed exactly, using a nonlinear solver minimizing (for instance):
$$ \left( \log( y ) - f(\gamma,\{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N; x^* \right)^T\left( \log( y ) - f(\gamma,\{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N; x^* \right) $$
in $(\gamma, \{\beta_{0t}\}_{t=1}^T,\{\beta_{1n}\}_{n=1}^N ).$
Note that it a bit is strange that apples (consumption ?) determine income, usually it is the other way round. With this specification,  individuals have an incentive to buy apples in order to increase their income,... indefinitely if apples are cheap enough: endogeneity occurs, but it is not a problem here, as there is no random term.
Here is a R-code illustrating the claim:
# -------------------------
library(optimx)

dat_dum_T = rbind(1,1) %x% matrix( c( rep( 0, 8 ), rep( 1, 21 )), ncol=1 ) 
dat_dum_N = diag(1,nrow=2) %x% rep( 1, 29 )

colnames( dat_dum_N ) <- c( paste0("dum_N_", 1:2 ) )

#
# This function computes the sum of squared residuals for different 
# parameter values
#
SSR_f = function( param, Data=DT ){
  
  gamma = param[1]
  par_dum_N = matrix( param[2:3], ncol=1 )
  par_dum_T = param[4]

  rownames( par_dum_N ) = paste0( "beta_N_", seq(1:2))

  ln_y = Data[,"ln_Y"]
  x_obs = Data[,"observed"]

  dum_N = par_dum_N[1]*dat_dum_N[,1] + par_dum_N[2]*dat_dum_N[,2] 
  dum_T = par_dum_T*dat_dum_T
    
  # The observed and true x are related by 
  # x_nt = x_obs_nt/dum_n + par_dum_t

  SSR = as.numeric( sum( ( ln_y - gamma*( log( x_obs/dum_N - dum_T ) ) )^2 ) )
  return( SSR )
}

true_val = c( 0.3, 1, 0.5, 0.3 )
SSR_f( true_val, DT )

par_0 = c( 0.5, 0.5, 1, 0 )
names(par_0) = c( "gamma","dum_N_1","dum_N_2", "dum_T" )

# check if starting values are admissible (and cause no numerical problem)
SSR_f( par_0, DT )

# The nonlinear numerical minimization procedure
optimx( par=par_0, fn=SSR_f, method="Nelder-Mead", control = list( trace=4, maxit=1000 ) )

> **Comments:**
> **username_0**: Hi @username_1, thanks for replying. I did not think of doing it this way, and tbh I'm not too familiar with nonlinear solvers, but what this is saying is that if I try to minimize the distance between observed and predicted log income (under a specific form for the predicted log income), then I can estimate the parameters. Why did you say that this would not work if there was an error term? Doesn't the solver compute (with certain confidence intervals) the same parameters, even if there is an error term?  
> **username_0**: Also, what if I relax the econometrician's understanding of the form of the relationship?  e.g. $$x_{nt}^{*} = \delta_na_tx_{nt}+u_t+b_n+\epsilon_{nt}$$ OR $$x_{nt}^{*} = \delta_n(a_tx_{nt}+u_t+b_n)+\epsilon_{nt}$$  This would still work, right? I would just use the nonlinear solver for each functional form of the relationship that I suspect, and then compare estimates given different functional forms, correct? As long as $NT>2N+2T+1$?  
> **username_1**: @username_0: I wanted to say that if you set $\varepsilon_{nt}=0$ in $$ \log( y_{nt} ) = \gamma \log( x_{nt})+\varepsilon_{nt},$$ then the (nonlinear) sum of squared residuals will be exactly zero in your case, and the solution will be exact and not random.  I should add a R code in my answer... to illustrate the claim. When $\varepsilon_{nt}$ is there, it is better not trying to estimate the "incidental" parameters but rather parameters of their distribution. See Wooldridge textbook for details. In your example $N=2$ and $T=29$ the sample is too small to obtain "good" parameter estimates.  

---

