

www.gllamm.org  
How do I create frequency weights to speed up gllamm?
Using frequency weights is a very useful and also an easy way to speed up
Using frequency weights means that the data are in collapsed form.
Thus, creating frequency weights is the same as collapsing the data
and the Suppose there is a dataset that contains students nested within schools. In the imaginary dataset, you have four variables schid stuid y sex schid and stuid are school and student identifiers, respectively.
y and sex are a binary response variable and a binary explanatory variable for the students.
Many students in the same school will have the same response and sex;
therefore, we can collapse the data and create level1 frequency weights using the commands:
generate cons=1 collapse (count) wt1 = cons, by(schid sex y)Above, the collapse command creates the weight variable wt1
by counting the number of cases in the combination of schid , sex , and y .
Namely, wt1 represents the number of cases who have the same response and sex in the same school.
Level2 frequency weights are most likely to be useful when the response variable is binary and the number of level1 units per level2 unit is small. Examples are longitudinal data or item responses in item response models. The weights represent the number of level2 units with the same set of responses and covariate values for its level1 units. The data should be in wide form, with one row of data for each level2 unit and separate variables for each level1 unit. For example, consider a longitudinal dataset in wide form with variables y1 y2 y3 y4 sex y1 to y4 are the responses at timepoints
1 to 4 and sex is a binary explanatory variable.
Many subjects will have the same sex and the same responses at the four
timepoints; therefore we can collapse the data and create level2
frequency weights using the commands:
generate cons=1 collapse (count) wt2 = cons, by(y1 y2 y3 y4 sex)
Before we can run generate pattern = _n reshape long y, i(pattern) j(occasion)Here pattern is now the new level2 identifier that should
be used in the i() option of the gllamm
command.
Examples and documentation


