Hello,
I am working with a panel dataset that provides information on any monetary gifts that a person received. In addition, there are variables that indicate in what year each gift was received. Thus, in Wave 3, Person A may be recorded having received a $500 gift. However, the gift may have actually been received in Wave 1. Accordingly, I want to create variables that equal the value of the total gift(s) received during the year the gift(s) was received.
My dataset looks like this:
However, I want it to look like this:
As you can see, I want to add up all the gifts recorded as being received in the same year. In the dataset above, you can see that respondent 111 received multiple gifts in 2007. The total of these gifts is $450, which is indicated in the tgift column. Furthermore, you can see that I want missing values to be recorded as zeros. For instance, respondent 111 received no gifts in 2010, so their tgift value is zero.
Frankly, I am stuck on how to approach this and would sincerely appreciate any guidance.
I am working with a panel dataset that provides information on any monetary gifts that a person received. In addition, there are variables that indicate in what year each gift was received. Thus, in Wave 3, Person A may be recorded having received a $500 gift. However, the gift may have actually been received in Wave 1. Accordingly, I want to create variables that equal the value of the total gift(s) received during the year the gift(s) was received.
My dataset looks like this:
Code:
clear input id time gift1 gift2 g1year g2year 111 2010 100 200 2007 2008 111 2009 50 150 2009 2007 111 2008 25 125 2008 2007 111 2007 75 . 2007 . 222 2010 200 300 2010 2009 222 2009 75 275 2008 2007 222 2008 . . . . 222 2007 . . . . end
Code:
clear input id time gift1 gift2 g1year g2year tgift 111 2010 100 200 2007 2008 0 111 2009 50 150 2009 2007 50 111 2008 25 125 2008 2007 225 111 2007 75 . 2007 . 450 222 2010 200 300 2010 2009 200 222 2009 75 275 2008 2007 300 222 2008 . . . . 75 222 2007 . . . . 275 end
Frankly, I am stuck on how to approach this and would sincerely appreciate any guidance.
Comment