• Stata to SPSS

    From Amit Kumar@21:1/5 to All on Sat Feb 20 22:27:13 2021
    Hello All,

    How can I run the same command in SPSS?
    bysort hhid: egen hhincome=total(totalinc)

    where hhid is my key variable.

    Thanks in advance.
    Amit

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich Ulrich@21:1/5 to amit@cbgaindia.org on Sun Feb 21 23:04:56 2021
    On Sat, 20 Feb 2021 22:27:13 -0800 (PST), Amit Kumar
    <amit@cbgaindia.org> wrote:

    SUBJECT: Stata to SPSS ( should have been in the text, too )
    Hello All,

    How can I run the same command in SPSS?
    bysort hhid: egen hhincome=total(totalinc)

    where hhid is my key variable.


    If Bruce is not on vacation, he might pop in with an answer,
    since he uses Stata.

    Else, you /could/ describe what the command does ...
    <Google> it looks like bysort does what Split Files does.

    If you just want to get totals for categories of hhid,
    you would Aggregate on hhid, getting SUM(totalinc).

    And
    [cribbed from an older message by Bruce]

    The SPSS mailing list (http://spssx-discussion.1045642.n5.nabble.com/)
    is a lot more active than this forum these days. You might want to
    join that list (if not already a member) and post your question there.
    Via the page given above, click on -more options- near the top for
    info on how to subscribe. HTH.

    --
    Rich Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to Rich Ulrich on Fri Jun 25 08:28:52 2021
    On Sunday, February 21, 2021 at 11:05:04 PM UTC-5, Rich Ulrich wrote:
    On Sat, 20 Feb 2021 22:27:13 -0800 (PST), Amit Kumar
    <am...@cbgaindia.org> wrote:

    SUBJECT: Stata to SPSS ( should have been in the text, too )
    Hello All,

    How can I run the same command in SPSS?
    bysort hhid: egen hhincome=total(totalinc)

    where hhid is my key variable.

    If Bruce is not on vacation, he might pop in with an answer,
    since he uses Stata.

    Else, you /could/ describe what the command does ...
    <Google> it looks like bysort does what Split Files does.

    If you just want to get totals for categories of hhid,
    you would Aggregate on hhid, getting SUM(totalinc).

    And
    [cribbed from an older message by Bruce]

    The SPSS mailing list (http://spssx-discussion.1045642.n5.nabble.com/)
    is a lot more active than this forum these days. You might want to
    join that list (if not already a member) and post your question there.
    Via the page given above, click on -more options- near the top for
    info on how to subscribe. HTH.

    --
    Rich Ulrich

    I did not see this until now, several months later. (My ISP stopped providing news server support, and the "new" and not so improved Google Groups does not notify me when new posts appear.) So this is no doubt too late for the OP, but I'll post it for
    the archives. The following AGGREGATE command in SPSS will give the same result as the OP's line of Stata code:

    AGGREGATE
    /OUTFILE=* MODE=ADDVARIABLES
    /BREAK=hhid
    /hhincome=SUM(totalinc).

    Here is a demonstration, starting with Stata, and following with SPSS.

    // Start of Stata code
    // Use data file from this UCLA tutorial to illustrate:
    // https://stats.idre.ucla.edu/stata/modules/reshaping-data-wide-to-long/

    use https://stats.idre.ucla.edu/stat/stata/modules/faminc, clear
    reshape long faminc, i(famid) j(year)
    list, clean noobs
    // Rename variables to match OPs variable names
    rename (famid faminc) (hhid totalinc)
    list, clean noobs
    // Now execute the OP's Stata code and list the results
    bysort hhid: egen hhincome=total(totalinc)
    list, clean noobs
    // End of Stata code

    *** Start of SPSS syntax ***.
    DATA LIST LIST / hhid year totalinc (3F8.0).
    BEGIN DATA
    1 96 40000
    1 97 40500
    1 98 41000
    2 96 45000
    2 97 45400
    2 98 45800
    3 96 75000
    3 97 76000
    3 98 77000
    END DATA.

    AGGREGATE
    /OUTFILE=* MODE=ADDVARIABLES
    /BREAK=hhid
    /hhincome=SUM(totalinc).

    LIST.
    *** End of SPSS syntax ***.

    Output from the final list command in the Stata code:

    . list, clean noobs

    hhid year totalinc hhincome
    1 96 40000 121500
    1 97 40500 121500
    1 98 41000 121500
    2 96 45000 136200
    2 97 45400 136200
    2 98 45800 136200
    3 96 75000 228000
    3 97 76000 228000
    3 98 77000 228000

    Output from the LIST command in the SPSS code:

    hhid year totalinc hhincome

    1 96 40000 121500.0
    1 97 40500 121500.0
    1 98 41000 121500.0
    2 96 45000 136200.0
    2 97 45400 136200.0
    2 98 45800 136200.0
    3 96 75000 228000.0
    3 97 76000 228000.0
    3 98 77000 228000.0

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Amit Kumar@21:1/5 to Bruce Weaver on Fri Jun 25 11:30:02 2021
    On Friday, 25 June 2021 at 20:58:54 UTC+5:30, Bruce Weaver wrote:
    On Sunday, February 21, 2021 at 11:05:04 PM UTC-5, Rich Ulrich wrote:
    On Sat, 20 Feb 2021 22:27:13 -0800 (PST), Amit Kumar
    <am...@cbgaindia.org> wrote:

    SUBJECT: Stata to SPSS ( should have been in the text, too )
    Hello All,

    How can I run the same command in SPSS?
    bysort hhid: egen hhincome=total(totalinc)

    where hhid is my key variable.

    If Bruce is not on vacation, he might pop in with an answer,
    since he uses Stata.

    Else, you /could/ describe what the command does ...
    <Google> it looks like bysort does what Split Files does.

    If you just want to get totals for categories of hhid,
    you would Aggregate on hhid, getting SUM(totalinc).

    And
    [cribbed from an older message by Bruce]

    The SPSS mailing list (http://spssx-discussion.1045642.n5.nabble.com/)
    is a lot more active than this forum these days. You might want to
    join that list (if not already a member) and post your question there.
    Via the page given above, click on -more options- near the top for
    info on how to subscribe. HTH.

    --
    Rich Ulrich
    I did not see this until now, several months later. (My ISP stopped providing news server support, and the "new" and not so improved Google Groups does not notify me when new posts appear.) So this is no doubt too late for the OP, but I'll post it for
    the archives. The following AGGREGATE command in SPSS will give the same result as the OP's line of Stata code:

    AGGREGATE
    /OUTFILE=* MODE=ADDVARIABLES
    /BREAK=hhid
    /hhincome=SUM(totalinc).

    Here is a demonstration, starting with Stata, and following with SPSS.

    // Start of Stata code
    // Use data file from this UCLA tutorial to illustrate:
    // https://stats.idre.ucla.edu/stata/modules/reshaping-data-wide-to-long/

    use https://stats.idre.ucla.edu/stat/stata/modules/faminc, clear
    reshape long faminc, i(famid) j(year)
    list, clean noobs
    // Rename variables to match OPs variable names
    rename (famid faminc) (hhid totalinc)
    list, clean noobs
    // Now execute the OP's Stata code and list the results
    bysort hhid: egen hhincome=total(totalinc)
    list, clean noobs
    // End of Stata code

    *** Start of SPSS syntax ***.
    DATA LIST LIST / hhid year totalinc (3F8.0).
    BEGIN DATA
    1 96 40000
    1 97 40500
    1 98 41000
    2 96 45000
    2 97 45400
    2 98 45800
    3 96 75000
    3 97 76000
    3 98 77000
    END DATA.

    AGGREGATE
    /OUTFILE=* MODE=ADDVARIABLES
    /BREAK=hhid
    /hhincome=SUM(totalinc).

    LIST.
    *** End of SPSS syntax ***.

    Output from the final list command in the Stata code:

    . list, clean noobs

    hhid year totalinc hhincome
    1 96 40000 121500
    1 97 40500 121500
    1 98 41000 121500
    2 96 45000 136200
    2 97 45400 136200
    2 98 45800 136200
    3 96 75000 228000
    3 97 76000 228000
    3 98 77000 228000

    Output from the LIST command in the SPSS code:

    hhid year totalinc hhincome

    1 96 40000 121500.0
    1 97 40500 121500.0
    1 98 41000 121500.0
    2 96 45000 136200.0
    2 97 45400 136200.0
    2 98 45800 136200.0
    3 96 75000 228000.0
    3 97 76000 228000.0
    3 98 77000 228000.0

    Thanks Bruce for your response, Although I solved the issue in a different but long way.
    This will be useful in future if I face the same issue.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)