Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: SV: RE: SV: RE: SV: RE: RE: Sequence of numbers


From   "Tomas Lind" <[email protected]>
To   <[email protected]>
Subject   st: SV: RE: SV: RE: SV: RE: RE: Sequence of numbers
Date   Sun, 7 Mar 2010 17:47:41 +0100

I am performing (simulating) a case-control study and the clear deleted the
(saved) dataset with controls. After clear I made a new dataset with
id-numbers (not 1, 2, 3, 1, 2, 3) but 1, 2, 3 ... 1719, 1, 2 .... 1719, 1, 2
.. 1719 that I merged to the controls. Now I have a dataset with controls
with id-numbers that I can append to the dataset with cases. That works now.
However, maybe there is some easier way to draw say 3 controls (with and
without replacement) to each case in a dataset with exposure, cases and
(lots of) controls. 

/Tomas




-----Ursprungligt meddelande-----
Från: [email protected]
[mailto:[email protected]] För Martin Weiss
Skickat: den 7 mars 2010 17:31
Till: [email protected]
Ämne: st: RE: SV: RE: SV: RE: RE: Sequence of numbers


<>

I addition to Phil`s comment: -clear*- would kill all your -scalar-s anyway.


Just use a -local-, then:


*******
sysuse auto, clear
loc number = _N

clear*
set obs  `number'
egen byte myseq = fill(1 2 3 1 2 3)
*******

BTW, I am having a hard time imagining why you need to -clear- in between
and start anew. What`s the context?


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tomas Lind
Sent: Sonntag, 7. März 2010 16:55
To: [email protected]
Subject: st: SV: RE: SV: RE: RE: Sequence of numbers

Now I got stuck again when trying to merge my sequence variable to the
original dataset

"original dataset"
count
scalar number = r(N)


clear*
set obs  number
egen float myseq = fill(1 2 3 1 2 3)


Am I not allowed to use the scalar number together with -set obs-

/Tomas




-----Ursprungligt meddelande-----
Från: [email protected]
[mailto:[email protected]] För Martin Weiss
Skickat: den 7 mars 2010 16:39
Till: [email protected]
Ämne: st: RE: SV: RE: RE: Sequence of numbers


<>


" I didn´t understand how to make it
repeat itself."



Welcome to the club:
http://www.stata.com/statalist/archive/2009-04/msg00805.html


BTW, your original -expand- idea is probably more cumbersome than the
alternatives shown:

****
clear*
set obs 3
gen byte seq=_n
gen byte cl=1
expandcl 10, cluster(cl) generate(newcl)
sort newcl seq
drop cl newcl
l
****



HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tomas Lind
Sent: Sonntag, 7. März 2010 16:33
To: [email protected]
Subject: st: SV: RE: RE: Sequence of numbers

Oh, thanks again. I tried -fill- but I didn´t understand how to make it
repeat itself.

:) Tomas



-----Ursprungligt meddelande-----
Från: [email protected]
[mailto:[email protected]] För Martin Weiss
Skickat: den 7 mars 2010 16:30
Till: [email protected]
Ämne: st: RE: RE: Sequence of numbers


<>

-egen, fill()- would have taken you there as well:


*******
clear*
set obs 99
egen float myseq = fill(1 2 3 1 2 3)
l
*******


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Sonntag, 7. März 2010 16:26
To: [email protected]
Subject: st: RE: Sequence of numbers


<>

*******
clear*
set obs 99
egen byte myseq = seq(), from(1) to(3) block(1)
l
*******


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tomas Lind
Sent: Sonntag, 7. März 2010 16:23
To: [email protected]
Subject: st: Sequence of numbers

Dear Listers,

Is it possible to generate a variable with a sequence of numbers that
repeats itself, for example 1, 2, 3, 1, 2, 3, 1, 2, 3.

I tried -egen fill- but that didn´t work. Another solution would be to make
a new dataset with tree lines with the values 1, 2, 3 and use -expand- and
finally merge that together with the first dataset. However it would be nice
if someone had a simple solution of how to do it within the dataset.

/Tomas


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


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


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


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index