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:

  • #2
    Duplicate post. Asked and answered at https://www.statalist.org/forums/for...m-of-variables.

    Please read the Forum FAQ. Bumping is strongly discouraged. Especially after only 5 minutes. Patience is a virtue, and a necessary one here on Statalist. If you do not receive a response to your question within a day, it might be reasonable to ask it again. But in doing so, one should continue the same thread, and the question should be rephrased. Usually when questions go unanswered, it is because it is unclear. So when reposting a question, it is best to ask it differently.

    But it is never appropriate to bump after only 5 minutes.

    Comment

    Working...
    X