Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • cmset for panel data


    Hi everyone, I am trying to run a choice model but constantly get an error when trying to run cmset. The data is based on survey data with three waves. this is the code I am running:
    Code:
     cmset id wave votechoice
    The alternatives variable votechoice offers the same choices in all three rounds, yet I constantly get the following error message:
    all choice sets have only one alternative
    What does that mean? Thank you for your help! -Hannah

  • #2
    Perhaps your data shows the choice of the voter and does not include the alternatives that were available to the voter. Consider the structure of the following dataset:

    Code:
    webuse transport.dta, clear
    list if id==1, sepby(t)
    Res.:

    Code:
    . list if id==1, sepby(t)
    
          +------------------------------------------------------------------------+
          | id   t       alt   choice   trcost   trtime   age   income    parttime |
          |------------------------------------------------------------------------|
       1. |  1   1       Car        1     4.14     0.13   3.0        3   Full-time |
       2. |  1   1    Public        0     4.74     0.42   3.0        3   Full-time |
       3. |  1   1   Bicycle        0     2.76     0.36   3.0        3   Full-time |
       4. |  1   1      Walk        0     0.92     0.13   3.0        3   Full-time |
          |------------------------------------------------------------------------|
       5. |  1   2       Car        1     8.00     0.14   3.2        5   Full-time |
       6. |  1   2    Public        0     3.14     0.12   3.2        5   Full-time |
       7. |  1   2   Bicycle        0     2.56     0.18   3.2        5   Full-time |
       8. |  1   2      Walk        0     0.64     0.39   3.2        5   Full-time |
          |------------------------------------------------------------------------|
       9. |  1   3       Car        1     1.76     0.18   3.4        5   Part-time |
      10. |  1   3    Public        0     2.25     0.50   3.4        5   Part-time |
      11. |  1   3   Bicycle        0     0.92     1.05   3.4        5   Part-time |
      12. |  1   3      Walk        0     0.58     0.59   3.4        5   Part-time |
          +------------------------------------------------------------------------+

    "id" is the individual identifier, "t" is time variable ("wave" in your case), and "alt" is the set of alternatives available to the individual. The individual's choice is indicated by the variable "choice" which is a dummy variable. So if "votechoice" indicates the voter's choice in your dataset, Stata interprets this as the set of alternatives in the cmset command, and hence the error message that all choice sets have one alternative. If you have access to the alternatives available to each voter, you can restructure your dataset as above. If not, you do not have choice model data.

    Comment


    • #3
      Hi Andrew,
      now I understand - thank you! The alternatives variable does indeed only show the actual choice the person made at time t, and not the range of options it would have had ... thank you so much.
      All best
      Hannah

      Comment


      • #4
        Hi Andrew,

        do you have an easy way of reshaping the data in the right format so I can cmset it?

        Respondents had to respond to a question that read if you had an emergency and you needed 300 USD, how would you pay for those expenses and there were 6 response options.

        Code:
        list if id==62, sepby(t)
        
        
               +--------------------------------------------------------------------------------+
               | id   t   emerge~1   emerge~6   emerge~2   emerge~3   emerge~4   emerge~5   age |
               |--------------------------------------------------------------------------------|
           55. | 62   1        Yes          .         No         No         No         No    67 |
               |--------------------------------------------------------------------------------|
           56. | 62   2        Yes         No         No         No         No         No    71 |
               |--------------------------------------------------------------------------------|
           57. | 62   3        Yes         No         No         No         No         No    72 |
               +--------------------------------------------------------------------------------+
        My data format is already in a long format so I don't really now how to use reshape in this case.

        I have tried the following code.

        Code:
        reshape long emergency_, i(id) j(yr)
        drop if emergency_ == 0
        
        forvalues i = 1/6 {
            gen emergency_`i' = (`i' == _k)
        }
        drop emergency_ _k
        I would highly appreciate your help on this!
        Thank you!

        Comment


        • #5
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(id t emergency1 emergency6 emergency2 emergency3 emergency4 emergency5 age)
          62 1 1 . 0 0 0 0 67
          62 2 1 0 0 0 0 0 71
          62 3 1 0 0 0 0 0 72
          end
          label values emergency1 emergency
          label values emergency6 emergency
          label values emergency2 emergency
          label values emergency3 emergency
          label values emergency4 emergency
          label values emergency5 emergency
          label def emergency 1 "Yes", modify
          label def emergency 0 "No", modify
          
          rename emergency* choice*
          reshape long choice, i(id t) j(alt)
          list, sepby(id t)
          cmset id t alt
          Res.:

          Code:
          . list, sepby(id t)
          
               +-----------------------------+
               | id   t   alt   choice   age |
               |-----------------------------|
            1. | 62   1     1      Yes    67 |
            2. | 62   1     2       No    67 |
            3. | 62   1     3       No    67 |
            4. | 62   1     4       No    67 |
            5. | 62   1     5       No    67 |
            6. | 62   1     6        .    67 |
               |-----------------------------|
            7. | 62   2     1      Yes    71 |
            8. | 62   2     2       No    71 |
            9. | 62   2     3       No    71 |
           10. | 62   2     4       No    71 |
           11. | 62   2     5       No    71 |
           12. | 62   2     6       No    71 |
               |-----------------------------|
           13. | 62   3     1      Yes    72 |
           14. | 62   3     2       No    72 |
           15. | 62   3     3       No    72 |
           16. | 62   3     4       No    72 |
           17. | 62   3     5       No    72 |
           18. | 62   3     6       No    72 |
               +-----------------------------+
          
          . 
          . cmset id t alt
          note: case identifier _caseid generated from id and t.
          note: panel by alternatives identifier _panelaltid generated from id and alt.
          
                              Panel data: Panels id and time t
                        Case ID variable: _caseid
                   Alternatives variable: alt
          Panel by alternatives variable: _panelaltid (strongly balanced)
                           Time variable: t, 1 to 3
                                   Delta: 1 unit
          
          Note: Data have been xtset.

          Comment


          • #6
            Hi Andrew,

            thank you so much for your help!!

            All best,
            Hannah

            Comment

            Working...
            X