Announcement

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

  • Help Finding # of Observations

    Hello, after bysorting a variable, I was having trouble finding the number of observations of the new bysorted variables. Any help would be greatly appreciated. The Code is

    bysort CUME_ACE07: logit opioids i.CUME_D71H2 i.Bace2 i.Demale, or base

  • #2
    finding the number of observations of the new bysorted variables
    This is ambiguous.

    It could mean you want to know the number of observations that each value of CUME_ACE07 appears in. If that's what you mean:
    Code:
    by CUME_ACE07, sort: gen wanted = _N
    It could mean you want to know how many distinct values of CUME_ACE07 takes on. In that case:
    Code:
    sort CUME_ACE07
    gen wanted = sum(CUME_ACE07 != CUME_ACE07[_n-1]
    replace wanted = wanted[_N]
    But perhaps you even intend some other meaning that I have not thought of. Because it is difficult for me to discern the relevance of the -logit- command you show to any of this.

    If neither of my suggestions is what you have in mind, when posting back, please use the -dataex- command to post some example data, and then show what the desired results would be for the example, along with an explanation of how you would arrive at those results if you had to do the calculation by hand.

    If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X