Announcement

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

  • check that rangestat is used correctly

    Hello,

    My data has the following variables: symbol (to identify which firm it is), year, industry and mandatory (a dummy variable =1 if the firm is "mandatory"). I want to compute the proportion of firms that are "mandatory" by a given industry and a given year excluding the focal firm. After reading https://www.statalist.org/forums/for...ding-own-value and https://www.statalist.org/forums/for...interval-t-1-0, I wrote the following:

    Code:
    sort Year industry Symbol
    rangestat (mean) mandatory_prop=mandatory, interval(Year 0 0) by(industry) excludeself
    I'd appreciate it if you could let me know if my code looks reasonable. I have a further question, it may be obvious but I really don't know (my apologies), how can I kind of "extract" the value of mandatory_prop when mandatory=1 to make it a new variable, as that I can use it as a variable in the regression.

    Thanks!
    Last edited by Flora Yin; 03 Sep 2021, 23:31.

  • #2
    or alternatively, according to what Nick Cox wrote in another post:

    mean of others = total of others / (#observations - 1)
    = (sum of all MINUS this value) / (#observations -1)

    if I want to calculate the proportion of mandatory firms relative to all firms in a given industry in a given year, I could do the following and subtract both numerator and denominator by 1 (because mandatory is a dummy variable, I simply count how many mandatory are there rather than calculating the average):

    Code:
    sort Year industry Symbol
    
    bysort Year industry:egen M=count(status) if status==mandatory
    bysort Year industry:egen Mmean=mean(M)
    bysort Year industry:egen all=count(status)
    gen Mmean1=Mmean-1
    gen all1=all-1
    gen mandatory_prop = Mmean1 / all1
    I tried both in #1 and #2 and they give the same answer. So either they are both right or both wrong. Please kindly give me some suggestions.

    Thanks!
    Last edited by Flora Yin; 03 Sep 2021, 23:32.

    Comment


    • #3
      rangestat is from SSC.

      The recipe in #2 should give the same answer so long as there are no missing values. on mandatory.

      mandatory_prop is a new variable, so I don't understand that part.


      Comment


      • #4
        Hi Nick,

        Thanks for your reply! Yes I do realize now mandatory_prop is a new variable, so please ignore this part.

        Comment

        Working...
        X