You can put your sequences in string variables.
bysort id (t) : gen y_seq = string(y[1])
by id : replace y_seq = y_seq[_n-1] + string(y) if _n > 1
by id : replace y_seq = y_seq[_N]
and similarly for the other variable.
Then you select just observation for each panel
egen tag = tag(id)
tab y_seq yhat_seq if tag, chi2
Nick
[email protected]
Nikolaos Kanellopoulos
> I want to estimate the Pearson Goodness of fit after a Random Effects
> Probit. To do that I need to count the frequencies of each
> sequence that my
> actual variable (y) and its prediction (yhat)have.
>
> For instance in the following example y takes 3 sequences by
> id and t 0001,
> 0000, 0011 with frequencies 2 ,1, 1 respectively and yhat
> takes 0001, 0000,
> 1000, 0011 each with frequency 1. My problem is that I can't count the
> different sequences that y and yhat follow.
>
> Any help is more than welcome.
>
> +-------------------+
> id t y yhat
> -------------------
> 1. 1 1 0 0
> 2. 1 2 0 0
> 3. 1 3 0 0
> 4. 1 4 1 1
> 5. 2 1 0 0
> -------------------
> 6. 2 2 0 0
> 7. 2 3 0 0
> 8. 2 4 1 0
> 9. 3 1 0 1
> 10. 3 2 0 0
> -------------------
> 11. 3 3 0 0
> 12. 3 4 0 0
> 13. 4 1 0 0
> 14. 4 2 0 0
> 15. 4 3 1 1
> -------------------
> 16. 4 4 1 1
> +-------------------+
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/