Announcement

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

  • set n(#) in a kdensity loop with different sample sizes

    Hi Statalist, I am new here but this forum is been helpful several times.

    I am using stata15, and there's my problem:

    I have a large amount of datasets, and I am looping them in order to produce kdensities and compare them. Each dataset has a different sample size.
    I am entering the following command inside my loop:

    kdensity variable, generate(x y) n() nograph

    I am trying to find a way to put automatically the sample size inside the option n().

    If I write:

    count
    kdensity variable, generate(x y) n(r(N)) nograph

    stata says: option n() not allowed r(198);
    It happens the same if I try to use a local with r(N)

    How can I do? I would avoid to make them one-by-one


    Last edited by Andrea Stochino; 08 Apr 2019, 05:00.

  • #2
    These methods work. Note that you don't need
    Code:
    count
    beforehand.

    Code:
    .   sysuse auto, clear
    (1978 Automobile Data)
    
    . kdensity mpg , n(`c(N)')
    
    . kdensity mpg , n(`=_N')
    Naturally if you have missing values, the number of observations used will be fewer.

    Comment


    • #3
      I tried it inside my loop and it works.
      I guessed that solution had to be very simple but I was not able to find a way.

      Now it is solved, thanks a lot

      Comment

      Working...
      X