Statalist


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

st: RE: RE: Use foreach or forvalues to create the long form data


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Use foreach or forvalues to create the long form data
Date   Thu, 16 Oct 2008 13:35:52 +0100

Martin's advice looks good. 

But Anupit's question doesn't hang together for me. The specific example, and even longer ones of the same form, don't strike me as -reshape- questions at all as they involve creating new data in structured form. 

By the way, for large datasets make sure to use -egen long- or -egen double- if you need to. 

But if you had a -reshape- question, strict sense, I doubt you could speed things up much by programming it yourself with -forvalues- or -foreach-. That would, broadly speaking, mean that you were a better Stata programmer than the Stata developers. There could well be exceptions, but I'd guess that this statement would be true much more often than its converse. 

Nick 
[email protected] 

Martin Weiss

- h egen,seq()-

Supnithadnaporn, Anupit

Would you please suggest me how to create data in the long form
by *not* using reshape? I would like to avoid reshape because reshape
takes very very long time. In fact, the final & total number of records 
that I have to create would be around 12,000,000.

I think foreach and forvalues can do this work. 
But, I am a novice in Stata programming and could not figure out so far.

In the beginning, I have only Obsid which is created by

gen Obsid = _n

The desired data would look like this:

Obsid   Vid     Imp
1       1       1
2       1       2
3       1       3
4       1       4
5       2       1
6       2       2
7       2       3
8       2       4

...


100     25      4


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index