Hi everyone
I have a question about saving the residuals in panel data.
Features of my dataset are as follows:
1) # of panel: 300
2) time id: 1 to 400
example of the dataset can be shown as
Let's say there is an equation:
weekly_sales (i,t) = a + b*weekly_sales(i,t-1) + resid
What I want to acquire is the residuals of the equation above.
I tried the code below, but I think the result is not what I was looking for.
------
gen resid_weekly_sales=.
levelsof(company_id), local(local_company_id)
foreach id of local local_company_id {
regress weekly_sales L.weekly_sales if company_id==`id'
predict r if company_id==`id', resid
replace resid_weekly_sales = r if company_id==`id'
drop r
}
------
I think the reason why the results are wrong is that I did not account for time_id in the coding.
I would appreciate it if someone can help me figure out the solution.
Thank you.

I have a question about saving the residuals in panel data.
Features of my dataset are as follows:
1) # of panel: 300
2) time id: 1 to 400
example of the dataset can be shown as
company_id | time_id | weekly_sales |
1 | 1 | 100 |
1 | 2 | 150 |
1 | 3 | 170 |
1 | 4 | 120 |
1 | 5 | 125 |
weekly_sales (i,t) = a + b*weekly_sales(i,t-1) + resid
What I want to acquire is the residuals of the equation above.
I tried the code below, but I think the result is not what I was looking for.
------
gen resid_weekly_sales=.
levelsof(company_id), local(local_company_id)
foreach id of local local_company_id {
regress weekly_sales L.weekly_sales if company_id==`id'
predict r if company_id==`id', resid
replace resid_weekly_sales = r if company_id==`id'
drop r
}
------
I think the reason why the results are wrong is that I did not account for time_id in the coding.
I would appreciate it if someone can help me figure out the solution.
Thank you.
Comment