SPSS Statistics

 View Only
  • 1.  Restructuring long to wide

    Posted Wed September 20, 2023 06:12 PM

    Hi all.  I have a long dataset where the same respondents have multiple rows ( range 1-10 rows per person). In the rows are a variable events and variables of dates starting and ending the event and reasons why the event starts and ends.  The reasons contain 15 different categorical variables ( numeric). I want to restructure from long to wide.  But the coding I've tried scrambles the data.   Some respondents can have multiple events in one year. 
    when restructured I want the data to be date event1 reason event1 date end 1 reason end 1.  And so onup to 10 different groupings around each event.   Any ideas how to do this?    Julie



    ------------------------------
    Julie Selwyn
    ------------------------------


  • 2.  RE: Restructuring long to wide

    Posted Thu September 21, 2023 03:03 PM

    Have you already tried this?  


    VARSTOCASES
    /make var from var1 to var10
    /keep=id.



    ------------------------------
    Art Jack
    ------------------------------



  • 3.  RE: Restructuring long to wide

    Posted Thu September 21, 2023 04:34 PM
    Sorry that doesn't work. Thanks for trying. Some respondents only have one row  while the max number of rows per person is 10.   Julie 

    Sent from my iPhone





  • 4.  RE: Restructuring long to wide

    Posted Fri September 22, 2023 04:01 AM

    Hi Julie, I think SPSS casestovars command (i.e long to wide) requires balanced repeated measures, so you may need to balance the data before restructuring it.

    I suggest adding rows to the long format so that each respondent has the same number of rows (10). You only need the respondent ID filled in and

    the rest of the variables can be blank (missing) for these added cases.

     

    Graeme

    La Trobe University | TEQSA PRV12132 - Australian University | CRICOS Provider 00115M






  • 5.  RE: Restructuring long to wide

    Posted Fri September 22, 2023 04:41 AM
    Edited by Patrick Henry-Lucet Fri September 22, 2023 04:41 AM

    Hello there.

    You can use casestovars with different rows count for each event:

    CASESTOVARS
      /ID=event
      /GROUPBY=INDEX.



    ------------------------------
    Patrick Henry-Lucet
    ------------------------------



  • 6.  RE: Restructuring long to wide

    Posted Fri September 22, 2023 05:41 PM
    Many thanks Patrick that worked after first creating a new variable 'Counter' using the LAG function.  Thanks for everyone's suggestions.  Julie 

    Sent from my iPhone