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

From |
Nikhil Jha <n.jha.utd@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: data management question |

Date |
Wed, 25 Mar 2009 13:14:06 -0500 |

My apologies to all ...... The forval loop was to loop through every observation (189254) because when I tried earlier to use bys inside of forval, I got error message which I INCORRECTLY inferred that I could not use by within the loop (so basically wanted to loop by id and then pick up if any asc =1 and then generate assc=1 for all of that id). Appreciate your help. Your code is exactly what was needed.....I am sure my computer will eventually crank it out! Thank you also to others who were generous with their time. Nikhil On Wed, Mar 25, 2009 at 12:11 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > 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 > > 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/ > * * 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: data management question***From:*Nikhil Jha <n.jha.utd@gmail.com>

**st: RE: data management question***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: 2SLS with random effects correcting for autocorrelation** - Next by Date:
**st: Family expenditure survey UK** - Previous by thread:
**st: RE: data management question** - Next by thread:
**st: abbreviating a variable list in regression commands** - Index(es):

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