Statalist


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

st: RE: RE: variable that counts double observations..


From   Linn Renée Naper <linn.naper@ecgroup.no>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: variable that counts double observations..
Date   Wed, 12 Nov 2008 21:30:28 +0100

Hi
Thanks, I used the bysort group: gen var = ceil(_n/2) command. 
Perfect!
Linn

-----Opprinnelig melding-----
Fra: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] På vegne av Nick Cox
Sendt: 12. november 2008 16:09
Til: statalist@hsphsun2.harvard.edu
Emne: st: RE: variable that counts double observations..

First I note that your example syntax is quite illegal. However, 

bysort group: gen var = _n 

would work, for example. 

I take it that you want to generate a new variable with successive values 1,1,2,2,3,3,4,4, etc. 

Check out -egen-'s -seq()- function. 

Alternatively 

bysort group: gen var = ceil(_n/2) 

Nick 
n.j.cox@durham.ac.uk 

Linn Renée Naper

egen var=_n, by(group) will give me a variable counting from 1 til N within each group of the data. 
BUT: how do I tell stata that the observations are double in the sense that I need a variable that repeats each number ones, 
like this: 11 22 33 44.... instead of 1 2 3 4.....
I need this variable in order to collapse the data.


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