I am running a Diff-in-Diff fixed effects model, where I am evaluating a policy's impact at the neighborhood-level, and I am collapsing the outcome variable at the month-level.
However, I am trying to add controls for annual percentage changes for oil prices, which I suspect influences both my treatment and control observations. However, I have oil prices by year and at the country-level, rather than neighborhood-level.
I tried to create a variable capturing yearly percentage changes for oil prices as follows:
```
foreach v of varlist oil_avg {
gen change_`v' = D.`v'
}
replace change_oil_avg=0 if change_oil_avg==.
```
Here is a data example:
```
. dataex numeric_neighborhood oil_avg change_oil_avg hijri_yr month
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input long numeric_neighborhood float(oil_avg change_oil_avg hijri_yr month)
1 54.13 0 1438 76
2 79.61 0 1431 1
2 111.26 0 1432 4
2 111.63 0 1433 18
2 108.56 0 1434 34
3 64.3 0 1440 110
3 41.96 -22.340004 1441 111
3 41.96 0 1441 112
3 41.96 0 1441 115
3 41.96 0 1441 116
4 41.96 0 1441 113
4 41.96 0 1441 114
4 41.96 0 1441 117
5 111.63 0 1433 25
6 71.34 0 1439 95
7 108.56 0 1434 30
7 52.32 0 1436 53
7 52.32 0 1436 57
7 52.32 0 1436 62
7 43.64 0 1437 65
7 54.13 0 1438 79
```
I then added the "change_oil_avg" variable to the DiD model as follows:
```
xtreg tobacco_sales i.DiD_implementation i.change_oil_avg i.gender i.education i.month, fe cluster(numeric_neighborhood)
```
However, I keep receiving the following error message
```
change_oil_avg: factor variables may not contain noninteger values
```
Here is a data description of the "change_oil_avg" variable:
```
desc change_oil_avg
Variable Storage Display Value
name type format label Variable label
---------------------------------------------------------------------------------------------------------------------------
change_oil_avg float %9.0g
```
However, I am trying to add controls for annual percentage changes for oil prices, which I suspect influences both my treatment and control observations. However, I have oil prices by year and at the country-level, rather than neighborhood-level.
I tried to create a variable capturing yearly percentage changes for oil prices as follows:
```
foreach v of varlist oil_avg {
gen change_`v' = D.`v'
}
replace change_oil_avg=0 if change_oil_avg==.
```
Here is a data example:
```
. dataex numeric_neighborhood oil_avg change_oil_avg hijri_yr month
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input long numeric_neighborhood float(oil_avg change_oil_avg hijri_yr month)
1 54.13 0 1438 76
2 79.61 0 1431 1
2 111.26 0 1432 4
2 111.63 0 1433 18
2 108.56 0 1434 34
3 64.3 0 1440 110
3 41.96 -22.340004 1441 111
3 41.96 0 1441 112
3 41.96 0 1441 115
3 41.96 0 1441 116
4 41.96 0 1441 113
4 41.96 0 1441 114
4 41.96 0 1441 117
5 111.63 0 1433 25
6 71.34 0 1439 95
7 108.56 0 1434 30
7 52.32 0 1436 53
7 52.32 0 1436 57
7 52.32 0 1436 62
7 43.64 0 1437 65
7 54.13 0 1438 79
```
I then added the "change_oil_avg" variable to the DiD model as follows:
```
xtreg tobacco_sales i.DiD_implementation i.change_oil_avg i.gender i.education i.month, fe cluster(numeric_neighborhood)
```
However, I keep receiving the following error message
```
change_oil_avg: factor variables may not contain noninteger values
```
Here is a data description of the "change_oil_avg" variable:
```
desc change_oil_avg
Variable Storage Display Value
name type format label Variable label
---------------------------------------------------------------------------------------------------------------------------
change_oil_avg float %9.0g
```
Comment