Announcement

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

  • Generate the sum of conditional variable


    Hi all! I am a freshman for the State software and now have a question to ask you.
    I want to calculate the sum of WithdrawJan WithdrawFeb WithdrawMar WithdrawApr WithdrawMay WithdrawJun WithdrawJUL by the year 2005, 2006, 2007 and 2008. I want my final outcome is a single value and in a single column. Such as:
    WUDSpriID eFactspriID Year Month Withdraw
    ID1 ID1 2005 Jan XXX
    ID1 ID1 2005 Feb XXX
    ID1 ID1 2005 Mar XXX
    ID1 ID1 2005 Apr XXX
    ID1 ID1 2005 May XXX
    ID1 ID1 2005 Jun XXX
    ID1 ID1 2005 Jul XXX

    ID1 ID1 2006 Jan XXX
    ID1 ID1 2006 Feb XXX
    ID1 ID1 2006 Mar XXX
    ID1 ID1 2006 Apr XXX
    ID1 ID1 2006 May XXX
    ID1 ID1 2006 Jun XXX
    ID1 ID1 2006 Jul XXX

    ID1 ID1 2007 Jan XXX
    ID1 ID1 2007 Feb XXX
    ID1 ID1 2007 Mar XXX
    ID1 ID1 2007 Apr XXX
    ID1 ID1 2007 May XXX
    ID1 ID1 2007 Jun XXX
    ID1 ID1 2007 Jul XXX

    My first step is to generate Withdraw_Jan = sum(WithdrawJan) if Year = 2005 and apply the command to 2006 2007 2008. But the stata is always shows a invalid syntax error. Could you please help me to fix that error? And if it is allowed, Could you please give me a suggestion how to transform the dataset below to the dataset format I want above?
    The version I use is STATA 14. Thank you very much!

    Here is my data set:
    Click image for larger version

Name:	2018-07-17 下午9.55.42.png
Views:	2
Size:	488.4 KB
ID:	1453914


  • #2
    Triplicate post, only 1 minute after the duplicate, which followed the original by only 5 minutes.

    Asked and answered at the original: https://www.statalist.org/forums/for...m-of-variables.

    Please understand that Statalist is a community of users who help each other as and when they wish to. It is not a help line and nobody is under any obligation to respond to anything, let alone to do so quickly. If your question is so urgent that you must have an answer within a few minutes, then you need to find some other source of help that commits itself to rapid response. Statalist is not that kind of resource. And rapid bumping feels abusive in our context.

    Comment

    Working...
    X