Announcement

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

  • Save count value as a variable

    Hi,

    I want to count the number of observations within a certain range of another variable. For example, I want to count number of individuals in my data set with a taxable income between 380 000 and 420 000 in a certain year.
    My count value is 72272. I now would like to save that value as a variable, no be able to use it in a calculation in the next line of code even if I switch data set.

    My code so far is:

    count if z>=380000 & z<=420000 & year==2
    //= 72272
    gen H = ?

    How can i replace H = 72272 without doing it manually?


    Thank you for your time!

    /Oskar

  • #2
    the -count- command saves its result in r(N) as shown in the help file - so you could
    Code:
    gen H=r(N)
    immediately after your count command

    but why do you want a variable that is a constant? there are probably better ways to get where you are going but you don't really give enough information - please read the FAQ

    Comment


    • #3
      Originally posted by Rich Goldstein View Post
      the -count- command saves its result in r(N) as shown in the help file - so you could
      Code:
      gen H=r(N)
      immediately after your count command

      but why do you want a variable that is a constant? there are probably better ways to get where you are going but you don't really give enough information - please read the FAQ
      Fantastic, thank you.

      Comment

      Working...
      X