Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Teething troubles in using -gen, mod()-


From   jean ries <[email protected]>
To   [email protected]
Subject   Re: st: Teething troubles in using -gen, mod()-
Date   Wed, 02 Feb 2005 11:53:35 +0100

Clive,

I think you should sort your data by id after expanding. In fact, the observations created by -expand- are added to the end of the data set. Try this:

. expand 5
. sort id
. gen alt = mod(_n,5)

Hope this helps,

jean


Clive Nicholas wrote:


All,

Hiya! I'm attempting to create an -expand-ed dataset by creating a copy of
every observation (-id-) for each category of a multinomial variable
(-gewin-). There are five categories in total.

The data was already carefully checked and -sort-ed. After some very
careful reading of appropriate sources, I thought I'd cracked it with the
following:

. use mydata

. expand 5
(10496 observations created)

. gen alt = mod(_n, 5)

. sort id election alt

Thus, each duplicated observation within each quintet should take a unique
value of -alt-, from 0-4. Unfortunately, the new variable does not
-generate- as it should for the vast majority of groups:

. list id pano election name1997 gewin edyear alt in 1/30, sepby(id)

+--------------------------------------------------------+
| id pano election name1997 gewin edyear alt |
|--------------------------------------------------------|
1. | 1 1 1 Aberavon 2 1976 0 |
2. | 1 1 1 Aberavon 2 1976 1 |
3. | 1 1 1 Aberavon 2 1976 1 |
4. | 1 1 1 Aberavon 2 1976 2 |
5. | 1 1 1 Aberavon 2 1976 3 |
|--------------------------------------------------------|
6. | 2 1 2 Aberavon 2 1983 0 |
7. | 2 1 2 Aberavon 2 1983 1 |
8. | 2 1 2 Aberavon 2 1983 2 |
9. | 2 1 2 Aberavon 2 1983 2 |
10. | 2 1 2 Aberavon 2 1983 4 |
|--------------------------------------------------------|
11. | 3 1 3 Aberavon 2 1984 0 |
12. | 3 1 3 Aberavon 2 1984 1 |
13. | 3 1 3 Aberavon 2 1984 3 |
14. | 3 1 3 Aberavon 2 1984 3 |
15. | 3 1 3 Aberavon 2 1984 4 |
|--------------------------------------------------------|
16. | 4 1 3 Aberavon 2 1987 0 |
17. | 4 1 3 Aberavon 2 1987 2 |
18. | 4 1 3 Aberavon 2 1987 3 |
19. | 4 1 3 Aberavon 2 1987 4 |
20. | 4 1 3 Aberavon 2 1987 4 |
|--------------------------------------------------------|
21. | 5 1 3 Aberavon 2 1986 0 |
22. | 5 1 3 Aberavon 2 1986 1 |
23. | 5 1 3 Aberavon 2 1986 2 |
24. | 5 1 3 Aberavon 2 1986 3 |
25. | 5 1 3 Aberavon 2 1986 4 |
|--------------------------------------------------------|
26. | 6 1 4 Aberavon 2 1988 0 |
27. | 6 1 4 Aberavon 2 1988 1 |
28. | 6 1 4 Aberavon 2 1988 1 |
29. | 6 1 4 Aberavon 2 1988 2 |
30. | 6 1 4 Aberavon 2 1988 3 |
+--------------------------------------------------------+

If I'm missing something obvious here, it's very esoteric.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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