[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> |

Subject |
st: RE: data management question |

Date |
Wed, 25 Mar 2009 17:11:42 -0000 |

If I understand this correctly, you want forval i = 1/2138 { bysort id (asc`i') : replace asc`i' = asc`i'[_N] } by id : keep if _n == _N Your original loop isn't executable code, and I don't understand it as pseudocode, but (again if I understand you correctly) you don't need a loop for that part anyway. Nick n.j.cox@durham.ac.uk Nikhil Jha I have a question related to data management. I have a fairly large data set in the following format: id asc1 asc2 asc3........ ___________________________________ 1 1 0 0 1 0 1 0 --------------------------------- 2 0 1 0 2 1 0 0 2 0 0 1 ---------------------------------- : : where id is the identifier and asc1, asc2, etc are associations related to specific ids. I would like to put it in this format eventually. id asc1 asc2 asc3........ ___________________________________ 1 1 1 0 2 1 1 1 : : My plan was to use reshape wide for which I needed it to first look like this: id asc1 asc2 asc3........ ___________________________________ 1 1 1 0 1 1 1 0 --------------------------------- 2 1 1 1 2 1 1 1 2 1 1 1 ---------------------------------- : : That is if ever a particular id is associated with any asc, that column is 1 for all occurrence of that particular id. This could probably be done with..... bysort id : g byte assc1 = sum(asc1) or collapse (sum) asc1-asc2138 , by (id) But my problem is that there are 2138 asc (i.e. last var is asc2138) [and not enough memory (see below) for collapse], so I want to automate this. So I tried to do a loop like: egen same = group(id) forvalues i =1/_N{ local j = 1 while `j'=same{ g ascc`j' =1 continue local j = `j'+1 } } But this just doesn't work - invalid syntax (using Stata 10). Any pointers (either for fixing this loop or the original problem) would be greatly 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/

**Follow-Ups**:**Re: st: RE: data management question***From:*Nikhil Jha <n.jha.utd@gmail.com>

**References**:**st: data management question***From:*Nikhil Jha <n.jha.utd@gmail.com>

- Prev by Date:
**st: RE: Programming: Capturing bysort-parameters for use within a program** - Next by Date:
**st: abbreviating a variable list in regression commands** - Previous by thread:
**st: AW: data management question** - Next by thread:
**Re: st: RE: data management question** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |