I have panel data and need to generate a new variable by taking the difference of variable "rent" for obs with variable "location" == "x" and obs with variable "location" == "y" if variable "time period" is the same. For example:
Obs 1 has time period = 2023, rent = 12 and location = x. I would like to generate a new variable for obs 1 by subtracting (rent for location "x" minus rent for location "y" from obs 2 (12-10)
Obs 2 has time period = 2023, rent = 10, and location =y .
Any help would be appreciated.
Obs 1 has time period = 2023, rent = 12 and location = x. I would like to generate a new variable for obs 1 by subtracting (rent for location "x" minus rent for location "y" from obs 2 (12-10)
Obs 2 has time period = 2023, rent = 10, and location =y .
Any help would be appreciated.
Comment