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 Darson <[email protected]>
To   [email protected]
Subject   Re: st: creating cross tables/ matrices with expected/ observed frequencies from long data set
Date   Mon, 24 Sep 2012 08:36:25 +1000

Nick, thanks for your reply.

The first question simply asked for a normal cross-table (with
frequencies of events A & B). I was able to get this through keep and
reshape (and saving matrices and matrices to dta- sets). Just took a
while.

The second table I am looking for is not a normal cross-table - I need
the product of a variable of two groups (classical matrix
multiplication) and I also cannot simply collapse the data set to one
observation per individual (as there are probabilities for each option
from each individual).
I can do this too by droping all variables, saving each data set,
converting it to a matrix in another set, then multiplying it and
saving it again...and so orth
Again just not very handy..... therefore I posted my questions and was
wondering whether anyone knows a command/ user written program that
would facilitate this analysis.. it seems like not... lesson learnt
(or maybe I used the wrong header/ described my problem not sufficient
enough).

In any case, I wanted to take the opportunity thank you and everyone
who contributes to this mailing list for their generous voluntary
support!!! This was one of the reasons why I decided to purchase a
permanent license for Stata 12!! so, thanks guys :-)

Nick Darson



On Sat, Sep 22, 2012 at 7:58 PM, Nick Cox <[email protected]> wrote:
> Sorry, but I am not clear how the second question differs from the first.
>
> One table you are asking for has 300 columns (one for each ID).
> Really?  When I have that many columns, I give up on conventional
> tables and just go for -list-s. -groups- (SSC) shows my strategy in
> action, although I am not promising that it is an answer to any
> problem of yours.
>
> On Sat, Sep 22, 2012 at 9:48 AM, Nick Darson <[email protected]> wrote:
>> Well, if there is not other solution, I guess I will have to reshape
>> the data. I just wanted to double check whether there is a "tab"-like
>> command that can create cross-tabs of different groups from the same
>> variable....
>>
>> What about the second question (for the expected frequencies)? Is
>> there any table function (in the sense of "list") that simply shows
>> the values of a group from a variable instead of describing its
>> summary/ modes/ etc?
>>
>> BTW: Thanks for the reply, Nick!
>>
>>
>>
>> On Sat, Sep 22, 2012 at 5:16 PM, Nick Cox <[email protected]> wrote:
>>> 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/

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