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

  • Filipp Sabitzer
    started a topic Count specific values in a column

    Count specific values in a column

    Hi all,

    please consider the following table.
    A CountA
    1 3
    1 3
    1 3
    2 1
    3 2
    3 2
    4 3
    4 3
    4 3
    In my data set column A is given. I would like to compute the second column. The values are calculated based on how many times the value in the same row of column A occurs in total in column A. For example, the first row: the value 1 occurs 3 times in column A. Hence, in CountA there is a 3 for all 1s. Is there a specific count demand that can be used to do this?

    I appreciate any help. Thank you.

  • Clyde Schechter
    by A. sort, gen: countA = _N
    Please don't use the terms row and column when referring to Stata data sets. That terminology is appropriate for spreadsheets, but Stata is not a spreadsheet. And if you try to do things in Stata based on your habits from using spreadsheets, you will often find yourself going far astray. So it is important to keep the terminology separate in your mind: Stata datasets have variables and observations, not columns and rows.

    Do read -help by- to learn about the -by:- prefix and how it works with _n and _N.

    Leave a comment: