Hi,
I wonder whether there are limitations to the number of variables one can list after the by command?
Is it possible for instance to use a command like this:
by a b c d e f g, sort: gen x=1 if a==1 & b==2 & c==1 & d==1 & e==2 & g==3
Or how about this:
by a b c year id date, sort: gen x=_n if a==1 & b==1 & c==0
Would this command eventually sort by "id" and "date" within "id"? What would then be the difference compared to the following:
by a b c year id (date), sort: gen x=_n if a==1 & b==1 & c==0
Would one of these commands create the a list of "_n" sorted by id and date within id given all those other "bys" and "ifs"?
I want something looking like this (randomly created in excel - did not fill in all the dates, just the ones I am interested in):
Thankful for any advice.
I wonder whether there are limitations to the number of variables one can list after the by command?
Is it possible for instance to use a command like this:
by a b c d e f g, sort: gen x=1 if a==1 & b==2 & c==1 & d==1 & e==2 & g==3
Or how about this:
by a b c year id date, sort: gen x=_n if a==1 & b==1 & c==0
Would this command eventually sort by "id" and "date" within "id"? What would then be the difference compared to the following:
by a b c year id (date), sort: gen x=_n if a==1 & b==1 & c==0
Would one of these commands create the a list of "_n" sorted by id and date within id given all those other "bys" and "ifs"?
I want something looking like this (randomly created in excel - did not fill in all the dates, just the ones I am interested in):
a | b | c | year | id | date | _n |
0 | 1 | 0 | 2004 | x | ||
0 | 1 | 0 | 2004 | x | ||
0 | 1 | 0 | 2004 | x | ||
0 | 1 | 0 | 2004 | x | ||
0 | 1 | 0 | 2004 | x | ||
0 | 1 | 0 | 2004 | xx | ||
0 | 1 | 0 | 2005 | xx | ||
0 | 1 | 0 | 2005 | xx | ||
0 | 1 | 1 | 2004 | x | ||
0 | 1 | 2 | 2004 | x | ||
0 | 1 | 2 | 2005 | xx | ||
0 | 2 | 0 | 2004 | x | ||
0 | 2 | 0 | 2004 | x | ||
0 | 2 | 0 | 2005 | x | ||
0 | 2 | 0 | 2006 | xx | ||
0 | 2 | 1 | 2004 | y | ||
0 | 2 | 1 | 2004 | xx | ||
0 | 2 | 2 | 2004 | x | ||
0 | 2 | 2 | 2005 | xx | ||
1 | 1 | 0 | 2004 | a | 1.1.2004 | 1 |
1 | 1 | 0 | 2004 | a | 2.1.2004 | 2 |
1 | 1 | 0 | 2004 | a | 3.1.2004 | 3 |
1 | 1 | 0 | 2004 | a | 4.1.2004 | 4 |
1 | 1 | 0 | 2004 | a | 5.1.2004 | 5 |
1 | 1 | 0 | 2004 | b | 1.1.2004 | 1 |
1 | 1 | 0 | 2004 | b | 2.1.2004 | 2 |
1 | 1 | 0 | 2005 | a | 1.1.2005 | 1 |
1 | 1 | 0 | 2005 | a | 2.1.2005 | 2 |
1 | 1 | 0 | 2005 | b | 1.1.2005 | 1 |
1 | 1 | 0 | 2005 | b | 2.1.2005 | 2 |
1 | 1 | 0 | 2005 | c | 1.1.2005 | 1 |
1 | 1 | 0 | 2005 | c | 2.1.2005 | 2 |
1 | 1 | 0 | 2006 | a | 1.1.2006 | 1 |
1 | 1 | 0 | 2006 | a | 2.1.2006 | 2 |
1 | 1 | 0 | 2006 | b | 1.1.2006 | 1 |
1 | 1 | 0 | 2006 | c | 1.1.2006 | 1 |
1 | 1 | 1 | 2004 | a | ||
1 | 1 | 1 | 2005 | b | ||
1 | 1 | 2 | 2006 | c | ||
1 | 2 | 0 | 2004 | a | ||
1 | 2 | 0 | 2004 | a | ||
1 | 2 | 0 | 2005 | a | ||
1 | 2 | 0 | 2006 | b | ||
1 | 2 | 1 | 2004 | b | ||
1 | 2 | 1 | 2004 | c | ||
1 | 2 | 1 | 2004 | c | ||
1 | 2 | 2 | 2006 | c |
Comment