Dear community members,
I would like to add a new column, say NEW, composed of adjusted R^2. To be specific:
1. I have two columns representing uniqueID and Date, respectively. So, first, I would like to create subsets of the original data composed of each unique ID sorted by Date. I believe it can be done, using the command “by UniqueID Date.”
2. From there, I would like to perform regressions, using the previous 12 observations in each subset, and extract an adjusted R^2. Obviously, the first 12 observations in each subset will not have a corresponding adjusted R^2. I don’t mind it. So, if "i" represents the uniqueID and "t" represents Date, NEW_{i, t}: = R^2 from the regression based on observations from {i, t-12} to {i, t-1}. I will use e(r2_a) to extract adjusted R^2.
Would there be a way to perform this in Stata? My biggest problem for now is how to use a certain number of observations (12 in my case) in regression.There could be some cases where fewer than 13 observations exist in some subsets, as the number of "t"s varies across each "i". In that case, I hope corresponding values in a NEW column will be missing values. I know as long as at least one independent variable in a regression contains a missing value, that observation(s) will be omitted. Nevertheless, I would like to use exactly 12 previous observations.
Any advice would be greatly appreciated.
I would like to add a new column, say NEW, composed of adjusted R^2. To be specific:
1. I have two columns representing uniqueID and Date, respectively. So, first, I would like to create subsets of the original data composed of each unique ID sorted by Date. I believe it can be done, using the command “by UniqueID Date.”
2. From there, I would like to perform regressions, using the previous 12 observations in each subset, and extract an adjusted R^2. Obviously, the first 12 observations in each subset will not have a corresponding adjusted R^2. I don’t mind it. So, if "i" represents the uniqueID and "t" represents Date, NEW_{i, t}: = R^2 from the regression based on observations from {i, t-12} to {i, t-1}. I will use e(r2_a) to extract adjusted R^2.
Would there be a way to perform this in Stata? My biggest problem for now is how to use a certain number of observations (12 in my case) in regression.There could be some cases where fewer than 13 observations exist in some subsets, as the number of "t"s varies across each "i". In that case, I hope corresponding values in a NEW column will be missing values. I know as long as at least one independent variable in a regression contains a missing value, that observation(s) will be omitted. Nevertheless, I would like to use exactly 12 previous observations.
Any advice would be greatly appreciated.