st: managing data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

st: managing data

Rodrigo Briceño-4
Dear Statalisters. I have a database of individuals with have suffered
from some events (muscular pain). The maximum amount of events an
individual could suffer in the database is 4. What I need is to copy
the information available (the row of data for each individual) the
number of times required, so those individuals that have 3, 2 or 1
event,  end in the new database with 4 events all. So for example
(maximum number of events is 2 in this case):

old database:
id event x
1  1      30
2  1      15
2  2      15

new database
id event x
1  1      30
1  1      30
2  1      15
2  2      15

I'm using stata 9 and my OS is windows vista. Thanks for your help.


--
Rodrigo Briceño
Economist
+506  22-91-12-00 ext. 113   Office
+506  22-32-08-30                Fax
+506  88-86-11-77                Cell
[hidden email]
[hidden email]

MSN: [hidden email]
SKYPE: rbriceno1087

*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: managing data

David Elliott
It is unclear from your example what you are trying to accomplish.

In your example, is event a summary count?  If so, I can't reconcile the

old database:
id event x
1  1      30
2  1      15
2  2      15

with what you have in

new database
id event x
1  1      30
1  1      30
2  1      15
2  2      15

You could (almost) create your new database from the old using
-fillin id event-

this would give you:

    +---------------------------+
     | id   event    x   _fillin |
     |---------------------------|
  1. |  1       1   30         0 |
  2. |  1       2              1 |
  3. |  2       1   15         0 |
  4. |  2       2   15         0 |
     +---------------------------+

then
-replace x=x[_n-1] if _fillin-

would give you:

    +---------------------------+
     | id   event    x   _fillin |
     |---------------------------|
  1. |  1       1   30         0 |
  2. |  1       2   30         1 |
  3. |  2       1   15         0 |
  4. |  2       2   15         0 |
     +---------------------------+

however, event in row 2 is a '2' rather than a '1' which may defeat
your purpose.

Look at -help fillin- and -help expand- and consider the possibility
of doing something with -bysort id:- depending on the value of _N.

Anyhow, a more complete example would be helpful.

DCE
*
*   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/
David Elliott MD, MSc
Nova Scotia Dept. of Health
Reply | Threaded
Open this post in threaded view
|

st: RE: managing data

Nick Cox
In reply to this post by Rodrigo Briceño-4
I share David Elliott's concerns here.

This does not seem a well posed problem to me, quite apart from appearing a very weird request without some rationale.

First, the example contradicts the description. In your example, individuals end up with 2 events each.

Second, what rule do you have for expanding your events to 4 each? If individuals have 1 event each, that could be copied three times. But if individuals have 2 or 3 events each, which is to be copied to fill out the data?

More generally, as I can't see that data management here can (or should purport to) create information that doesn't exist, it would be interesting to know the problem behind this problem, as I guess there's a better solution to it than this.

Nick
[hidden email]

Rodrigo Briceño

I have a database of individuals with have suffered
from some events (muscular pain). The maximum amount of events an
individual could suffer in the database is 4. What I need is to copy
the information available (the row of data for each individual) the
number of times required, so those individuals that have 3, 2 or 1
event,  end in the new database with 4 events all. So for example
(maximum number of events is 2 in this case):

old database:
id event x
1  1      30
2  1      15
2  2      15

new database
id event x
1  1      30
1  1      30
2  1      15
2  2      15

I'm using stata 9 and my OS is windows vista. Thanks for your help.

*
*   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/