SPSS Statistics

 View Only
  • 1.  Creating a dummy variable that becomes 1 when conditions are fulfilled in other data entries?

    Posted Tue April 23, 2024 12:58 PM

    Hi,

    I have been struggling for a long time with a very specific thing that I am trying to get out of SPSS. Essentially the dataset that I am working in contains information about commercial flights over time. A data entry shows information on things like average price, distance and so on for a specific carrier in a specific year on a specific route.

    Some of these carriers are low cost carriers, and I have created a dummy variable to identify each data entry that contains all this info for a low cost carrier. What I am trying to implement now is another dummy variable that indicates whether in the year on the specific route there is an LCC operating or not. In other words, when computing the variable I need SPSS to check for a specific data entry what the values for route and year are, and then it should check all other data entries with the same year and route. If there is at least 1 data entry in this group where the low cost dummy has a value of 1, then the variable should also be 1. This way I can see on what routes in which time periods airline carriers are competing with low cost carriers. To make things simpler I already made an additional variable "route_yr" which is simply a unique variabale containing info on the route and the year at the same time.

    I think it should be possible but long time struggling myself with the LAG function as well as resorting to ChatGPT have not been able to bring me any further yet. Thanks!



    ------------------------------
    Brent Van Campenhout
    ------------------------------


  • 2.  RE: Creating a dummy variable that becomes 1 when conditions are fulfilled in other data entries?

    IBM Champion
    Posted Tue April 23, 2024 04:04 PM
    This is doable using the SPSSINC TRANS

    --





  • 3.  RE: Creating a dummy variable that becomes 1 when conditions are fulfilled in other data entries?

    IBM Champion
    Posted Tue April 23, 2024 04:13 PM
    This is doable using the SPSSINC TRANS extension command with the vlookup function in the extendedTransforms.py file installed with SPSS.  You create a dataset with a variable that is the concatenation of all the elements of the lookup key.  It can have whatever other variables you want as the values to be returned as one or more variables.

    You then use SPSSINC TRANS with extendedTransforms.vlookup, giving it the concatenated key, and specifying the list of variables to create.  The rest would be straightforward.

    SPSSINC TRANS is typically preinstalled with SPSS, but it probably isn't the latest version, so it would be a good idea to update it via Extensions > Extension Hub.

    Here is a toy example from the doc in the extendedTransforms.py file.
    * Example using the SPSSINC TRANS extension command
    * The lookup table.
    data list free/ value(F8.0) akey(A1).
    begin data
    10 'a'
    20 'b'
    100 'z'
    end data.
    dataset name lookup.

    * The main dataset.
    data list free/x(f8.0) y(A2).
    begin data
    1 'a'
    2 'b'
    5 'a '
    10 ''
    1 'b'
    end data.
    dataset name main.
    dataset activate main.

    spssinc trans result = resultcodealpha
    /initial "extendedTransforms.vlookup('akey', 'value', 'lookup')"
    /formula func(y).

    --





  • 4.  RE: Creating a dummy variable that becomes 1 when conditions are fulfilled in other data entries?

    Posted Wed April 24, 2024 09:19 AM

    It sounds like you could just use regular conditionals with the flags you've created?  You could also use do repeat if there are hundreds of variables. 



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