Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: creating variable summarizing for each individual properties of other members of a group at t-1 |

Date |
Wed, 18 May 2011 19:34:01 +0100 |

I don't see how lack of balance affects the calculation. If something is not in the data, in effect something didn't exist then. The numbers will be wrong if that is wrong, but the Stata code is the same. On a different note, it is not a good idea to keep asking for help when (a) you haven't yet understood or tried out solutions given or (b) you don't explain what is wrong with solutions offered. Nick n.j.cox@durham.ac.uk Erik Aadland My apologies for that misunderstanding, Nick. My programming abilities are still modest and I mistakenly believed the code applied to the first problem. However, I am still struggling with both problems as my dataset is also unbalanced. I failed to inform you of this vital information. It did not occur to me that this information would impact the code. I am sorry. So, Jorge's code for the first problem produces the correct variable as long as the data is balanced. When unbalanced ind_ids occur with ind_entry = 1, they are not included in the sums/counts for/of the other ind_ids. See the following example dataset for more precise structure representation. year month yearmonth ind_id ind_entry 2003 11 11 2 0 2003 12 12 2 0 2004 10 22 2 1 2004 11 23 2 0 2004 12 24 2 1 2003 11 11 4 0 2003 12 12 4 1 2004 10 22 4 0 2004 11 23 4 0 2004 12 24 4 0 2003 11 11 56 0 2003 12 12 56 0 2004 1 13 56 1 2004 2 13 56 0 I greatly appreciate your help and input. Kind regards. Erik. ---------------------------------------- > From: n.j.cox@durham.ac.uk > To: statalist@hsphsun2.harvard.edu > Date: Wed, 18 May 2011 18:36:37 +0100 > Subject: RE: st: creating variable summarizing for each individual properties of other members of a group at t-1 > > 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 > n.j.cox@durham.ac.uk > > 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/

**References**:**st: creating variable summarizing for each individual properties of other members of a group at t-1***From:*Erik Aadland <erikaadland@hotmail.com>

**Re: st: creating variable summarizing for each individual properties of other members of a group at t-1***From:*Jorge Eduardo Pérez Pérez <perez.jorge@ur.edu.co>

**RE: st: creating variable summarizing for each individual properties of other members of a group at t-1***From:*Erik Aadland <erikaadland@hotmail.com>

**RE: st: creating variable summarizing for each individual properties of other members of a group at t-1***From:*Nick Cox <n.j.cox@durham.ac.uk>

*From:*Erik Aadland <erikaadland@hotmail.com>

- Prev by Date:
**RE: st: RE: correct egen command to calculate means - please help** - Next by Date:
**st: asclogit & margins** - Previous by thread:
- Next by thread:
- Index(es):