Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: creating variable summarizing for each individual properties of other members of a group at t-1
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: creating variable summarizing for each individual properties of other members of a group at t-1
Date
Wed, 18 May 2011 18:36:37 +0100
My code
bysort ind_id (yearmonth) : gen ind_score = sum(ind_entry)
by ind_id : replace ind_score = ind_score == 1 & ind_score[_n-1] != 1
sort yearmonth
gen all_score = sum(ind_score)
by yearmonth : replace all_score = all_score[_N]
replace all_score = all_score - ind_score
bysort ind_id (yearmonth) : gen prevscore = allscore[_n-1]
was certainly intended to solve your second problem. I've not tested it. Are you saying it doesn't? And if it doesn't what does it get wrong?
Nick
[email protected]
Erik Aadland
Thank you Nick and Jorge for your suggestions. They were very helpful, and I am very grateful.
Jorge, your suggested code below worked perfectly for my "first" variable.
I am still struggling with my "second" variable. In the "second" variable, I am trying to create a variable that for each ind_id counts the total number of other ind_ids, excluding the focal ind_id, in the dataset that have experienced ind_entry =1 at least once up until and including yearmonth -1. In other words, I am trying to create a variable that for each individual tracks the number of other entrants in the dataset up until and including yearmonth -1. I am trying to track ind_ids that have entered, not how many times they have entered.
Any and all input on this problem would be very much appreciated.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/