SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Select and Filter by Cases Based on Frequency

    Posted Wed June 12, 2024 04:35 PM

    Hello All, first time here.

    I want to select cases (rows) based on the frequency of a numerical value in a variable column, which are unique IDs. However, each ID may have 1 to 50 sessions, with each session listed as an individual row. 

    Variable Column: ID

    Rows: Individual sessions. 

    Essentially, I am looking for something like this, but I haven't gotten anything to work. 

    Compute if frequency of 'ID' is greater than 2 as '1' or else '0' to new variable called 'enough_sessions'. '1' would mean 'yes' enough sessions. Then,

    I would add 'enough_sessions = 1' and be able to perform other analyses on just those participant IDs with at least three sessions. 

    Any tips? Thank you!!!

    Colter



    ------------------------------
    Colter Clayton
    ------------------------------



  • 2.  RE: Select and Filter by Cases Based on Frequency

    Posted Wed June 12, 2024 06:52 PM
    Use AGGREGATE (Data > Aggregate) breaking on id and choose count as the statistic.  Then you can select your sample using that new variable > 2 or whatever.

    --





  • 3.  RE: Select and Filter by Cases Based on Frequency
    Best Answer

    Posted Fri June 14, 2024 09:00 AM

    i'd use addvariables in the aggregate.

    AGGREGATE OUTFILE=* mode=ADDVARIABLES /BREAK=id  /count=n.



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



  • 4.  RE: Select and Filter by Cases Based on Frequency

    Posted Fri June 14, 2024 11:48 AM

    This works perfectly, thank you! Also, how would I add to break with an additional variable? So, I have my 'ID' variable and I have an 'appoint_type' variable that has values from 1 to 5. If I want to break by 'ID' and 'appoint_type' when 'appoint_type' is equal to 1, how would I properly add that to the syntax? For example, 

    AGGREGATE OUTFILE=* mode=ADDVARIABLES /BREAK=id and appoint_type=1 /count=n.

    Additional syntax added in italics



    ------------------------------
    Colter
    ------------------------------



  • 5.  RE: Select and Filter by Cases Based on Frequency

    Posted Fri June 14, 2024 03:01 PM
    Edited by Art Jack Fri June 14, 2024 03:02 PM

    i think something simple like this would work.

    if appoint_type=1 flag=1.

    recode flag(missing=0).

    aggregate outfile =* /break id flag /count=n.

    or 

    aggregate outfile =* /break id appoint_type /count=n.

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



  • 6.  RE: Select and Filter by Cases Based on Frequency

    Posted Tue June 25, 2024 03:29 PM

    Thank you Art! 



    ------------------------------
    Colter Clayton
    ------------------------------



  • 7.  RE: Select and Filter by Cases Based on Frequency

    Posted Fri June 14, 2024 03:12 PM
    You can have any number of break variables in that list (no and) but would have to create a variable for the appoint_type = 1 expression.  

    --





  • 8.  RE: Select and Filter by Cases Based on Frequency

    Posted Tue June 25, 2024 03:46 PM

    This works perfectly, Jon. Thank you! 



    ------------------------------
    Colter Clayton
    ------------------------------