I have a problem with unbalanced panel data in Stata 14. I have data for a 30 day period, and I want my function to omit non-trading days, using the business calendar function. I use the the business calendar function as I, as an example, want Stata to treat the lagged variable for monday as friday (or previous trading day). However, when I try to set my data to panel data using xtset, they are not balanced.
My full process:
I Loaded Excel data in the following format (cmpny collumn contains 9 companies).

And ran the commandos in the following order:
And my business calendar looks like this:
I ran the commandos because I wanted to group companies using an ID variable (cmpnynum). I wanted to create a non-string variable for the dates, and I wanted to load the business calendar called BCAF, and lastly, set the data to panel. When I ran the last command, I got the error message that panels are unbalanced.
I have looked over my data, as it less than 200 rows. There are no missing return or volume values. Here are summary statistics after the commandos are applied:
Does anyone know how to get the data to be balanced? Does it have anything to do with how I apply the business calendar? I hope the question is not too trivial. I looked at Youtube, forums posts and Stata's own manuals. Maybe I overlooked something. Any help is really appreciated!
My full process:
I Loaded Excel data in the following format (cmpny collumn contains 9 companies).
And ran the commandos in the following order:
Code:
egen cmpnynum = group(cmpny) gen date2 = date(date,"MDY") bcal load BCAF gen date3 = bofd("BCAF", date2) xtset cmpnynum date3 xtset volume return
Code:
1. purpose "remove non trading days from sample" 2. dateformat mdy 3. range may172018 june152018 4. centerdate may172018 5. omit dayofweek (sa su) 6. omit date may282018
I have looked over my data, as it less than 200 rows. There are no missing return or volume values. Here are summary statistics after the commandos are applied:
summarize Variable | Obs Mean Std. Dev. Min > Max -------------+----------------------------------------------- > ---------- cmpny | 0 date | 0 return | 189 .0026109 .0121749 -.0363594 > .0267003 volume | 189 1667010 1807973 9684 > 8029422 sentiment | 270 .0227281 .0822689 -.2629529 > .2539589 -------------+----------------------------------------------- > ---------- cmmpnynum | 270 5 2.586784 1 > 9 date2 | 270 21335.5 8.671515 21321 > 21350 date3 | 189 10 6.071384 0 > 20
Does anyone know how to get the data to be balanced? Does it have anything to do with how I apply the business calendar? I hope the question is not too trivial. I looked at Youtube, forums posts and Stata's own manuals. Maybe I overlooked something. Any help is really appreciated!
Comment