Announcement

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

  • tabstat results

    Hi everyone and thank you all for the future help. I would like to know if there is a way to create 3 new variables in Stata from the output of tabstat. The results i obtain are the following:


    . tabstat StringencyIndex, s(p25 p50 p75) by(Date)

    Summary for variables: StringencyIndex
    by categories of: Date (Date)

    Date | p25 p50 p75
    ----------+------------------------------
    2/15/2020 | 8.333333 8.333333 8.333333
    2/16/2020 | 8.333333 8.333333 8.333333
    2/17/2020 | 8.333333 8.333333 8.333333
    2/18/2020 | 8.333333 8.333333 8.333333
    2/19/2020 | 8.333333 8.333333 8.333333
    2/20/2020 | 8.333333 8.333333 8.333333
    2/21/2020 | 8.333333 8.333333 8.333333
    2/22/2020 | 8.333333 8.333333 8.333333
    2/23/2020 | 8.333333 8.333333 8.333333
    2/24/2020 | 8.333333 8.333333 8.333333
    2/25/2020 | 8.333333 8.333333 19.44444
    2/26/2020 | 19.44444 19.44444 30.55556
    2/27/2020 | 19.44444 19.44444 30.55556
    2/28/2020 | 19.44444 19.44444 30.55556
    2/29/2020 | 19.44444 19.44444 30.55556
    3/1/2020 | 25 25 25
    3/2/2020 | 25 25 25
    3/3/2020 | 25 25 25
    3/4/2020 | 47.22222 47.22222 47.22222
    3/5/2020 | 47.22222 47.22222 47.22222
    --more--


    Now my question is: how can i create 3 new variables for each of the three columns (p25, p50, p75)? I want to do this in order to create an interquartile range graph with shaded area with the command twoway. I need this answer for my master thesis. Thank you, have a nice day!

  • #2
    Hello, welcome to Statalist.

    Clarification: Do you want to create a dataset that looks exactly like you posted, or do you want to merge this quartiles back to the original data set?

    Comment


    • #3
      I just want to add these 3 new variables to my original dataset. But if it is not possible to do this, it is ok also to create a new dataset with only these 3 variables.

      Comment


      • #4
        You can use the -egen pctile- command. Here is an example:

        Code:
        sysuse auto, clear
        
        bysort foreign: egen p25 = pctile(mpg), p(25)
        bysort foreign: egen p50 = pctile(mpg), p(50)
        bysort foreign: egen p75 = pctile(mpg), p(75)
        
        browse

        Comment


        • #5
          And if i want to sort for date i have to use
          bysort date: egen p25 = pctile(Stringencyindex), p(25)

          and so on?

          Comment


          • #6
            Originally posted by Isidoro Sinibaldi View Post
            And if i want to sort for date i have to use
            bysort date: egen p25 = pctile(Stringencyindex), p(25)

            and so on?
            Correct.

            Comment


            • #7
              Thank you very much, Ken. I really appreciate. I will try and let you know if it works or not. Have a nice day!

              Comment

              Working...
              X