Announcement

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

  • Help Using CountIf Function?

    Dear all,

    I am using Stata 16, on mac. I have taken a snapshot on the panel dataset I am working with.
    I used the following code:
    generate mlda_21 = 0 if mlda<21
    replace mlda_21 = 1 if mlda==21

    to create the dummy variable mlda_21 which equals 0 if the minimum drinking age is less than 21 and equals 1 if the minimum drinking age is = to 21
    I want to see how many states have a mlda of 21 for the year 1982. I was thinking of using the CountIf function?

    Thank you in advance for your help

    Jason Browen

    Click image for larger version

Name:	Screen Shot 2020-04-13 at 1.23.18 AM.png
Views:	1
Size:	10.3 KB
ID:	1546389
    Click image for larger version

Name:	Screen Shot 2020-04-13 at 1.18.51 AM.png
Views:	1
Size:	19.4 KB
ID:	1546387
    Click image for larger version

Name:	Screen Shot 2020-04-13 at 1.19.00 AM.png
Views:	1
Size:	8.5 KB
ID:	1546388

  • #2
    Please read https://www.statalist.org/forums/help#stata on why screenshots are not as helpful as you hope.

    Otherwise I am not aware of a CountIf function: this isn't MS Excel. But yes, there is a count command, so try


    Code:
    count if year == 1982 & mlda == 21
    https://www.stata.com/support/faqs/d...rue-and-false/ shows that

    Code:
    generate mlda_21 = mida == 21 if mida < .
    is a one-line alternative to your two statements.

    Comment


    • #3
      Thank you so very much Nick! It works great!

      Comment

      Working...
      X