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]
Re: Re: st: counting and immediately creating a new variable
From
"S.H. Former" <[email protected]>
To
[email protected]
Subject
Re: Re: st: counting and immediately creating a new variable
Date
Wed, 14 Sep 2011 11:42:21 +0200
brilliant! Is exactly what I needed, thanks very much
-----Original Message-----
From: Neil Shephard <[email protected]>
To: [email protected]
Date: Wed, 14 Sep 2011 10:33:13 +0100
Subject: Re: st: counting and immediately creating a new variable
On 14 September 2011 10:19, S.H. Former <[email protected]> wrote:
> Dear reader,
>
> I have a question concerning counting data and representing this count immediately in a new cell. The design of my dataset looks as follows:
>
>
> patent value complexity company
> 3930280 34 15 10679134
> 3930282 16 8 10577942
> 3930283 12 15 10577942
> 3930292 7 20 10151655
> 3930294 4 10 10680932
> 3930294 4 10 10680932
> 3930297 34 23 10105812
> 3930297 34 23 10105812
> 3930299 1 5 10204962
> 3930304 58 14 10046713
> 3930304 58 14 10046713
> 3930304 58 14 10046713
> 3930308 6 4 10140808
> 3930308 6 4 10140808
> 3930308 6 4 10140808
> 3930325 8 8 10446448
> 3930339 14 4 10120593
> 3930344 9 8 10030344
> 3930359 5 3 10107775
> 3930367 21 14 10446448
> 3930367 21 14 10446448
> 3930367 21 14 10446448
> 3930367 21 14 10446448
>
> Now I want to create a new variable where the number a patent is included in the database is counted. So it should look like this:
>
> patent value complexity company New Variable
> 3930280 34 15 10679134 1
> 3930282 16 8 10577942 1
> 3930283 12 15 10577942 1
> 3930292 7 20 10151655 1
> 3930294 4 10 10680932 2
> 3930294 4 10 10680932 2
> 3930297 34 23 10105812 2
> 3930297 34 23 10105812 2
> 3930299 1 5 10204962 1
> 3930304 58 14 10046713 3
> 3930304 58 14 10046713 3
> 3930304 58 14 10046713 3
> 3930308 6 4 10140808 3
> 3930308 6 4 10140808 3
> 3930308 6 4 10140808 3
> 3930325 8 8 10446448 1
> 3930339 14 4 10120593 1
> 3930344 9 8 10030344 1
> 3930359 5 3 10107775 1
> 3930367 21 14 10446448 4
> 3930367 21 14 10446448 4
> 3930367 21 14 10446448 4
> 3930367 21 14 10446448 4
>
> So for example take patent 3930294, you can see that there are two patents with this number so the new variable should give 2!
>
> Could please anyone help me with this problem?
>
bysort patent: gen n_patents = _N
This is probably useful...
http://www.stata-journal.com/article.html?article=pr0004
Neil
--
"To consult the statistician after an experiment is finished is often
merely to ask him to conduct a post mortem examination. He can perhaps
say what the experiment died of." ~ R.A. Fisher, Presidential Address
to the First Indian Statistical Congress, 1938
Neil Shephard
Clinical Trials Research Unit /
NIHR Research Design Service for Yorkshire & the Humber
University of Sheffield
*
* 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/