Currently, I am analyzing a panel data set where the dependent variable is a count variable. The dependent variable denotes the number of cars of a specific model in a month, with roughly 60 months.
Therefore, I constructed a negative binomial hierarchical model. My stan code looks like the following now for just one explanatory variable
This models the total number of activations over different countries. However, I also have the data available for each country. So, my explanatory variable looks like this:
Model Count Month Country
audi TT 34 02-2012 UK
audi TT 23 02-2012 DE
audi TT 20 02-2012 FR
etc
My ultimate goal is to make country-specific forecasts for the number of cars of a specific model in a specific month. Does anyone know how I could incorporate this in my multilevel model? I am not sure how i can do this with adding additional levels.
I would like to understand your hierarchy: Is it Country / Then Month or is it simply Country?
For the Country / Month structure to work you should have another level available. If not your hierarchy would be just one level. Do you have manufacturer (say GM) and brands within manufacturer (Chevrolet, Buick, Cadillac etc)?
My hierarchy is indeed Country then Month. Could you maybe also explain how I can add such a level in my existing code? Because my explanatory variable will then change from y_{it} (number of cars of model i at time t) to y_{ijt} (number of cars of model i in country j at time t) and I don’t see how that will work if I add a level with country-specific variables.
Next to that, I also have the manufacturer (GM) and brands within manufacturer (Chevrolet etc.). So an additional step will be to incorporate this into the model, but that will be more easy when I know how to do it with countries first.
Please follow the link to examine the setup of a 3 level multilevel model with RStan. The unit of observation is student, next level is class and the highest level is school id. Since I’m at work I can take a look your specific question much later. Hopefully this link will help you in the mean time. 3 Level Model with RStan
Another suggestion I would provide is to try to use the excellent tutorial by Paul Bliese on using R package multilevel with nlme to understand your data better. The link is PDF file with excellent coverage on multi-level modeling, the traditional way.
With the traditional parameters estimated, you would be in a better position to estimate your models using Stan. Hope these links are useful for you.
If I understand the example correctly, in my code I should add another level on top of the one I already have (in the alpha and zeta parameters where I currently have one level with variables multilevel)? And if I want this level to denote the country level I should add country-specific variables?
Sorry for all my questions but I am completely new to Stan.
Yes that is correct. I would ask you to proceed slowly if you are using Stan for the first time. Have you already examined the data in R with multilevel package and nlme? If not I would definitely recommend it.
Take a small sample of your data where you can define 2 levels. This would Country at the top and Manufacturers below (counts aggregated at the Manufacturer level by aggregating across months. Build the model with Stan (this forum has examples for two level models). Then in a similar dataset, add brand as a third level and work it out in Stan. In effect I’m saying take the time dimension out.
After you have figured out the structure and code without the time dimension, then bring it back. Another alternative is to work with all levels at the same time with a subset of the months, say 6 months. Select 2 Countries (US and Canada would work well), 2 common manufacturers, 2 common Brands and 6 months of data for each brand for a total of 48 records. Work out the structure and code.
Then setting up the full data will be child’s play. If you are not in a hurry, I’m trying to set up an example panel dataset that has 4 levels like you do and set up the RStan code. It will take me at least a week or so to set it up. If that will help you let me know and I will help you.