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: RE: histogram
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: histogram
Date
Thu, 14 Oct 2010 15:03:39 +0100
This is almost the function of -egen, tag()-.
egen tag = tag(id)
But with your problem, it is better to go back to first principles:
bysort id (mean) : gen tag = _n == 1
histogram mean if tag
The step of sorting within -id- was what you were missing.
Nick
[email protected]
Schöler, Lisa
I have different observations within one id:
Example
+----------------------------------+
| id mean(brand) brand year |
|--------------------------------|
| 1 5 7 1999 |
| 1 5 5 2000 |
| 1 5 3 2001 |
| 1 5 5 2002 |
| 1 . . 2003 |
|--------------------------------|
| id mean(brand) brand year |
|--------------------------------|
| 2 . . 1999 |
| 2 6 7 2000 |
| 2 6 8 2001 |
| 2 6 5 2002 |
| 2 6 4 2003 |
|--------------------------------|
| id mean(brand) brand year |
|--------------------------------|
| 2 . . 1999 |
| 2 6 7 2000 |
| 2 6 8 2001 |
| 2 6 5 2002 |
| 2 6 4 2003 |
+------------------------------+
Now I need to get a histogram that uses only one observation for each id for the mean(brand). Therefore I wanted to include a dummy=1, so I can use the command
. histogram if dummy==1
Can anybody help me how I can create a dummy=1 only for one observation per id? I was gonna use
. by id: gen dup = cond(_N==1,0,_n)
and then
. histogram if dup==1
But the problem here is that I have missings within my id groups, so sometimes my dup per id starts with 2.
If anybody has a better idea than creating a dummy, I am very happy to hear about it.
*
* 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/