Announcement

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

  • How to output a summary statistic according to a min/max value of another variable?

    Dear all,

    I am new to stata(list) and I want to create a descriptive statistic for my master thesis. Beside the regular output performed by the summarize command I am also interest in the summary statistic related to a min or a max value of a different variable.
    More precisely, the variable of interest is the mean of c_duration according to min and max values of other variables

    For instance, here is the regular output for c_duration and firms ( number of firms).

    summarize c_duration firms

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    c_duration | 123 87.77588 73.30465 2.1 424.8667
    firms | 123 5.219512 3.076981 2 17


    I know that I could in principle perform the analysis manually by,


    summarize c_duration if firms==2

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    c_duration | 19 69.83333 84.96852 2.1 312.4667



    summarize c_duration if firms==17

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    c_duration | 1 146.9333 . 146.9333 146.9333



    Since I have quite a few further variables I want to do it automatically with the foreach command.

    Thank you very much in advance!


    Niklas



  • #2
    Welcome to the Stata Forum / Statalist,

    Please take some time to read the FAQ. There you will find how to share command/data/output appropriately.

    That said, you just need to use a code similar to this one:

    Code:
    by catvar, sort: summarize numvar
    Best regards,

    Marcos

    Comment

    Working...
    X