Announcement

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

  • how to count observations in multiple variables

    Hi, I am a Stata beginner and want to see which observations meet certain criteria across 3 variables, I can not figure out how to do it. eg var1 more than 20, var2 more than 13, var3 everyone less than 150, I want to know who meets one or more of these. There must be a way but I've spent nearly 2 days searching for it!
    Many thanks

  • #2
    See

    Code:
    help operators
    Here, you need the or operator.

    Code:
    gen wanted= (var1>20 & !missing(var1)) | (var2>13 & !missing(var2)) | (var3<150)

    Missing is evaluated greater than everything, so we need to include the no missing conditions in the first two.

    Comment


    • #3
      Hannah, welcome. Please read this section with special focus on #9 to #12 thoroughly and follow the instructions for any post you make. This will help your chance of receiving a good reply.
      Roman

      Comment


      • #4
        hannah donnelly

        Welcome to Statalist, and to Stata.

        Let me add to this this discussion some advice I often give to posters who identify as new to Stata.

        I'm sympathetic to you as a new user of Stata - there is quite a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly. Nevertheless, I'd like to encourage you to take a step back from your immediate tasks.

        When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. All of these manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

        The objective in doing the reading was not so much to master Stata - I'm still far from that goal - as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

        Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

        Stata also supples YouTube videos, if that's your thing.

        Comment

        Working...
        X