Bookmark and Share

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   Erik Aadland <[email protected]>
To   <[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 17:28:45 +0000

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.
 
Thanks again and all the best.
 
Sincerely,
 
Erik Aadland.


> From: [email protected]
> Date: Wed, 18 May 2011 00:57:39 -0400
> Subject: Re: st: creating variable summarizing for each individual properties of other members of a group at t-1
> To: [email protected]
> 
> A rather complicated solution, but seems to work
> 
> bys ind_id (yearmonth): gen entry=sum(ind_entry)
> levelsof ind_id, local(lev)
> reshape wide ind_entry entry, i(yearmonth) j(ind_id)
> foreach x in `lev' {
> gen entryo`x'=(entry`x'>0)
> }
> foreach x in `lev' {
> unab vars: ind_entry*
> local vars: subinstr local vars "ind_entry`x'" ""
> egen fscore`x'=rowtotal(`vars')
> unab vars2: entryo* 
> local vars2: subinstr local vars2 "entryo`x'" ""
> egen fother_var`x'=rowtotal(`vars2')
> }
> drop entryo*
> reshape long ind_entry entry fscore fother_var, i(yearmonth) j(ind_id)
> xtset ind_id yearmonth
> gen score=l.fscore
> gen other_var=l.fother_var
> replace other_var=0 if other_var==.
> bys ind_id (yearmonth) : replace score=sum(score)
> drop fscore fother_var
> list
> 
> _______________________
> Jorge Eduardo Pérez Pérez
> 
> 
> 
> 
> On Tue, May 17, 2011 at 10:09 AM, Erik Aadland <[email protected]> wrote:
> >
> > Dear statalist.
> >
> > I need to create a variable that sums for each individual in my dataset the total number of ind_entry of all other individuals at time: yearmonth - 1.
> > I have attached a small ex of my data structure below. So for instance, given the small dataset below, for ind_id 2 in yearmonth 11 this variable score = 1. But for ind_id 4 in the same yearmonth, the score = 0.
> >
> > I would also like to generate a variable that identifies for each individual the unique number of other individuals in the dataset that have experienced ind_entry = 1 at least once up until time: yearmonth - 1.
> >
> > I am familiar with the following FAQ: http://www.stata.com/support/faqs/data/members.html
> >
> > My data structure is snapshot data in principle like the example below, but some individuals enter the observation window later than others (i.e. in later yearmonths):
> >
> > year month yearmonth ind_id ind_entry
> > 2003 10 10 2 0
> > 2003 11 11 2 0
> > 2003 12 12 2 0
> > 2004 1 13 2 0
> > 2004 2 14 2 1
> > 2004 3 15 2 0
> > 2003 10 10 4 1
> > 2003 11 11 4 0
> > 2003 12 12 4 1
> > 2004 1 13 4 0
> > 2004 2 14 4 0
> > 2004 3 15 4 0
> >
> > Any and all input is very welcome.
> >
> > Kind regards and all the best.
> >
> > Erik Aadland.
> > *
> > * 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/
> >
> 
> *
> * 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/ 		 	   		  
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index