Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: creating cross tables/ matrices with expected/ observed frequencies from long data set
Date   Sat, 22 Sep 2012 08:16:27 +0100

I think that this question is self-cancelling, as I guess that you
need to restructure your data to get tables that you want, but seem to
rule that out as an acceptable solution.

Nick

On Sat, Sep 22, 2012 at 1:35 AM, Nick Darson <[email protected]> wrote:

> 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.
>

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index