Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Darson <nick.darson@googlemail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: creating cross tables/ matrices with expected/ observed frequencies from long data set |

Date |
Sat, 22 Sep 2012 10:35:49 +1000 |

Dear Statalisters, I would like to create several tables/matrices with expected frequencies and observations (to be able to carry out a Chi Square test of how well my model describes the data). I have the following data set (each person chose from 2 sets, the first one containing 3 option, the second one containing 4 options), with ID=individuals (300), set=choice set, option= option, choice= chosen option (dummy), Prob= expected probability for each individual based on my random-effects logit model. ID Set Option Choice Prob 1 1 A 0 0.2 1 1 B 1 0.7 1 1 C 0 0.1 1 2 D 0 0.1 1 2 E 0 0.2 1 2 F 1 0.4 1 2 G 0 0.3 2…. First I would need a cross-table with observed frequencies for the two choice sets (looking as follows): A B C D E F G I am familiar with the tab-command, but a bit lost how do to obtain the table given my data-set arrangement? Any help would be appreciated. Then I would need the same table as above, but with expected (joint) probabilities instead of observed frequency. For this, I had the following strategy in mind: 1.) Create 2 matrices, one for each choice set 2.) Transpose one matrix and multiply to obtain joint probability For 1.), I would need one table with the probabilities listed (column= Individuals; rows= options) as follows: ID1 ID2 ID3 ….. A 0.2 ….. B 0.7 C 0.1 (and same table/ matrix for set 2). How would I do this in Stata? To my understanding, Tabs and tabstats only provide summaries etc, but I want the original value of prob listed? Any help would be appreciated! BTW: this is a simplification of the original data set (more sets and options) and I would like to do several things in one set…therefore, I “keep”/”reshape” combos would not be suitable. Cheers Nick * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: creating cross tables/ matrices with expected/ observed frequencies from long data set***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**RE: st: outsheet throws away varnames in unix** - Next by Date:
**Re: st: ivpois with a binary endogenous predictor** - Previous by thread:
**st: SEM for Time Series?** - Next by thread:
**Re: st: creating cross tables/ matrices with expected/ observed frequencies from long data set** - Index(es):