Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Count oberservations based on variable values

    Hello everyone,
    I have a number of patents that are sorted by patent number. For some patents there are several observations in which the pnumber is the same.
    I would now like to generate a variable that counts the number of observation per patentnumber. So lets say there are 3 observations for a unique patent number the value would be 3.
    Can anyone help me with this? I am new to Stata. Thank you in advance
    Best Regards
    tumseb

  • #2
    tumseb:

    Please use your full real name (FAQ Advice Section 6).

    Code:
     
    bysort pumber : gen freq = _N
    sounds pertinent. See also on the basics of by:

    SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q1/02 SJ 2(1):86--102 (no commands)
    explains the use of the by varlist : construct to tackle
    a variety of problems with group structure, ranging from
    simple calculations for each of several groups to more
    advanced manipulations that use the built-in _n and _N

    http://www.stata-journal.com/sjpdf.h...iclenum=pr0004

    and on distinct observations generally, including why "unique" is poor terminology for your situation:

    SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct observations
    (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
    Q4/08 SJ 8(4):557--568
    shows how to answer questions about distinct observations
    from first principles; provides a convenience command

    http://www.stata-journal.com/sjpdf.h...iclenum=dm0042

    Comment

    Working...
    X