data.frame(
bill = c(1L,1L,2L,2L,3L,3L,4L,4L,5L,5L,
6L,6L,7L,7L,8L,8L,9L,9L,10L,10L,11L,11L,12L,12L),
treat = c(0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,
0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L),
monthenergy = c(36.7032538284079,46.0402438841829,
32.9392795881018,41.2984949950169,28.1280279158878,
35.480098154243,24.9235110867169,31.8601494904683,25.8690610384381,
33.4558628130817,29.2486150406169,38.301071827994,
37.3012423685873,49.7570793648139,37.1106026686834,49.1615012450902,
38.0010307369504,50.4640419568872,25.6031441545062,
33.6860808231507,25.4171150782655,32.6026074847544,31.1551553278784,
39.2106574963103)
)
I need to generate a new variable, that is the difference between the treat=1 and treat=0 for each bill.