Announcement

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

  • count if function

    Hello,

    I have a query about using count if function. My data is arranged in Panel Data setting. For sake of simplicity, I keep it simple. My first column shows the year observation (2010, 2011, 2012) and the name of this variable is "Year". Second column records temperature values with the label "Temperature". It has both positive and negative numbers.

    I want to use "count if" function for counting positive and negative temperature values. For example if want to count observations with positive temperature I use this command "count if Temperature>0". But how can I change this command in order to know say the Positive Temperature values in the Year 2010?

  • #2
    How about

    count if Temperature>0 & Year == 2010
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      thank you. it worked

      Comment


      • #4
        Note that count is a command, not a function, and that if is here a qualifier. Small points of terminology, but it helps communication and learning to discuss Stata in Stata terms.

        Comment


        • #5
          thank you for your help. I have another question regarding count if command.

          how to use cont if command for example if I want to count positive temperature values "by" all years? I another words I want stata table to show positive temperature value by each year? I think we have to use "by" but I am not sure how.

          for example before using this command: (by Year: count if Temperature>0) Stata requires me to use "sort Year". This command arranges my Year data in ascending order. I do not want this change in my data actually. Therefore my questions is whether there is another way to do it ? Thanks a lot.

          Comment


          • #6
            Code:
             
            tab Year if Temp > 0

            Comment

            Working...
            X