<p>Here is a sketch of the code:</p>
<ol>
<li>Concatenate the sector and year, so it reads as &quot;energy1987&quot; or so.  They should be unique.</li>
<li>Encode this concatenated vector as a collection of binary dummies.</li>
<li>Use this set of dummies in the regression.</li>
</ol>
<p>But given a choice about reinventing the wheel, use the existing tools.</p>

CC BY-SA 4.0
2023-04-04T14:13:42.317Z
Would it work just by adding +Panel$Date * Panel$Secteur in the regressor like this ? :  plm(log(Panel$Prices)~ log(Panel$Electricity.price)+log(Panel$Gaz.Price)+ Panel$Date * Panel$Sector,  data=Panel, index= c("Sector","Date"), model="within",effect= "individual")
BAL
CC BY-SA 4.0
2023-04-01T10:46:25.727Z
2023-04-01T10:46:25.727Z
RegressForward
<p>I am trying to replicate the following econometric equation from the paper &quot;How do french manufacturing firms react to Energy shocks ?&quot;
<a href="https://i.sstatic.net/IAYHu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IAYHu.png" alt="enter image description here" /></a></p>
<p>s denotes sectors,i denotes firms, and t denotes year.
The paper uses panel data. As you see it has <span class="math-container">$\phi_i$</span> <strong>for firms fixed effects</strong>. I know how to implement such in R, I would use the following code:</p>
<pre><code>model1 &lt;- plm(log(Panel<span class="math-container">$Prices)~ log(Panel$</span>Electricity.pricr)+log(Panel$Gaz.Price)+
          data=Panel, index= c(&quot;Secteur&quot;,&quot;Date&quot;), model=&quot;within&quot;,effect= &quot;individual&quot;)
</code></pre>
<p>The command effect= &quot;individual&quot; enables me to have firm fixed effect.</p>
<p>However the paper includes also <strong>sector-year fixed effects <span class="math-container">$\chi_{st}$</span></strong>. But I do not know how to implement a fixed effect that plays on two variable at the same time: s and t. Do you know how I could implement it in R ?</p>
<p>Thank you</p>

CC BY-SA 4.0
2023-03-31T15:14:58.340Z
``interaction(secteur, year)`` seems to do the job. It generates a factor. You can add it as a regressor.
user18214
CC BY-SA 4.0
2023-03-31T16:02:46.113Z
Thank you, but how would you write that piece of code ?
BAL
CC BY-SA 4.0
2023-04-02T11:20:13.983Z
``model1 <- plm(log(Panel$Prices)~ log(Panel$Electricity.pricr)+log(Panel$Gaz.Price)+ interaction(Secteur, year),
          data=Panel, index= c("Secteur","Date"), model="within",effect= "individual")``
user18214
CC BY-SA 4.0
2023-04-02T11:20:28.213Z
Assuming you have a `year` variable
user18214
CC BY-SA 4.0
2023-05-01T13:23:23.940Z
Do you have a complete reference of the paper (maybe a link)? It is not possible to find it easily.
Bertrand
<econometrics><applied-econometrics><paneldata><data><fixed-effects>
Panel data with Sector year fixed effects on R
BAL
# Panel data with Sector year fixed effects on R

(Asked by: username_0 on 2023-03-31)

I am trying to replicate the following econometric equation from the paper "How do french manufacturing firms react to Energy shocks ?"
[![enter image description here](https://i.sstatic.net/IAYHu.png)](https://i.sstatic.net/IAYHu.png)

s denotes sectors,i denotes firms, and t denotes year.
The paper uses panel data. As you see it has $\phi\_i$ **for firms fixed effects**. I know how to implement such in R, I would use the following code:

```
model1 <- plm(log(Panel$Prices)~ log(Panel$Electricity.pricr)+log(Panel$Gaz.Price)+
          data=Panel, index= c("Secteur","Date"), model="within",effect= "individual")

```

The command effect= "individual" enables me to have firm fixed effect.

However the paper includes also **sector-year fixed effects $\chi\_{st}$**. But I do not know how to implement a fixed effect that plays on two variable at the same time: s and t. Do you know how I could implement it in R ?

Thank you

**Tags:** econometrics, applied-econometrics, paneldata, data, fixed-effects

> **Comments:**
> **username_1**: ``interaction(secteur, year)`` seems to do the job. It generates a factor. You can add it as a regressor.  
> **username_0**: Thank you, but how would you write that piece of code ?  
> **username_1**: ``model1 <- plm(log(Panel$Prices)~ log(Panel$Electricity.pricr)+log(Panel$Gaz.Price)+ interaction(Secteur, year),           data=Panel, index= c("Secteur","Date"), model="within",effect= "individual")``  
> **username_1**: Assuming you have a `year` variable  
> **username_2**: Do you have a complete reference of the paper (maybe a link)? It is not possible to find it easily.  

---

## 1 answers

### Answer by username_3 on 2023-04-01. Score: 1

Here is a sketch of the code:

1. Concatenate the sector and year, so it reads as "energy1987" or so. They should be unique.
2. Encode this concatenated vector as a collection of binary dummies.
3. Use this set of dummies in the regression.

But given a choice about reinventing the wheel, use the existing tools.

> **Comments:**
> **username_0**: Would it work just by adding +Panel$Date * Panel$Secteur in the regressor like this ? :  plm(log(Panel$Prices)~ log(Panel$Electricity.price)+log(Panel$Gaz.Price)+ Panel$Date * Panel$Sector,  data=Panel, index= c("Sector","Date"), model="within",effect= "individual")  

---

