Announcement

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

  • Generating third dummy variable in lagged period, that uses observations that are not equal to previously used observations

    I want to decompose a slope coefficient following Sias (2004) model. part 1 : I estimate this equation ∆k,t = βk,t-1 + εt

    Thus for each quarter, i estimate a cross sectional (across k stocks) regression of the standardized fraction of institutions buying stock k (∆k,t ) in the current quarter on the standardized fraction of institutions buying security k in the previous quarter (∆k,t-1 ). I then need to find an average β for all the quarters. (how do i average out the slope coefficient from all different quarters in the sample-see my code after regress)

    Second part : slope coefficient, β can be written as sum of series of dummy variables for each trader (that equal to one if the trader is a buyer (b) and zero if the trader is a seller(s)) divided by the number of traders (Nk, t
    ).

    The variables generated are described as below:

    Nk, t is the number of institutional investors trading stock k in quarter t and Dn,k,t is a dummy variable that equals one (zero) if the trader n is a buyer (seller) of stock k in quarter t.

    Nk, t-1 is the number of institutional investors trading stock k in quarter t-1, Dn, k, t-1 is a dummy variable that equals one (zero) if trader n is a buyer (seller) of stock k in quarter t-1,

    What am struggling with is this:
    to generate a dummy variable, Dm,k,t-1 that equals one (zero) if trader m (m!=n) (read m is not equal to n) is a buyer (seller) of stock k in quarter t-1.

    here is my code:
    Code:
    gen q_status=""
    replace q_status = "+" if q_position > 0
    replace q_status = "-" if q_position < 0
    replace q_status = "0" if q_position ==0
    To generate the dummy variables
    Code:
     gen Dq_status = cond(q_status == "+", 1, 0)
    bysort investor_id ticker (qdate) :gen Dnkt1 = Dq_status[_n-1]
    Code:
    egen id3= group(ticker qdate)
    sort id3
    by id3: egen n_buying = total(q_status == "+")
    by id3: egen n_selling = total(q_status == "-")
    gen rawDeltakt = n_buying/(n_buying + n_selling)
    by id3:gen Nkt = (n_buying + n_selling)
    bysort investor_id ticker (qdate) :gen LNkt = Nkt[_n-1]
    bysort qdate :gen RawDeltaL = rawDeltakt[_n-1]
    Code:
    bysort ticker (qdate) :gen ChangektL = Changekt[_n-1]
    bysort qdate: reg Changekt ChangektL
    my data looks like this

    Code:
    * Example generated by -dataex-. To install ssc install dataex
    * dataex date date2 investor_id stock buyerorseller value2 qdate q_position
    clear
    input int date str7 date2 byte investor_id str3 stock str1 buyerorseller double value2 str6 qdate long q_position
    21342 "Q2-2018" 1 "fb"  "b"   3545600 "2018q2"    3545600
    21530 "Q4-2018" 1 "fb"  "b"  42350000 "2018q4"  129000000
    21580 "Q1-2019" 1 "fb"  "b"   1886100 "2019q1"   17700000
    20984 "Q2-2017" 1 "il " "b"  43210000 "2017q2"   43200000
    21567 "Q1-2019" 1 "il " "b" 1.000e+08 "2019q1"   56800000
    20949 "Q2-2017" 1 "mc"  "b"  18865003 "2017q2"   17300000
    21413 "Q3-2018" 1 "mc"  "b"  58350000 "2018q3"   39500000
    21620 "Q1-2019" 1 "mc"  "b"   2612000 "2019q1"  -55700000
    20843 "Q1-2017" 1 "nb"  "b" 1426988.2 "2017q1" -138000000
    21656 "Q2-2019" 1 "nb"  "b"  64000000 "2019q2"   59800000
    21027 "Q3-2017" 1 "ns"  "s" -24200000 "2017q3"  -24200000
    20843 "Q1-2017" 1 "nc"  "b"  15000000 "2017q1"   38200000
    20968 "Q2-2017" 1 "nc"  "b"   4832000 "2017q2"  -31100000
    21434 "Q3-2018" 1 "nc"  "b"  26975000 "2018q3"   17400000
    21699 "Q2-2019" 1 "nc"  "b"  45294975 "2019q2"   18300000
    20846 "Q1-2017" 1 "nl"  "b"  40000000 "2017q1"   14900000
    21110 "Q4-2017" 1 "stb" "b" 1.500e+08 "2017q4"  145000000
    21413 "Q3-2018" 1 "stb" "b" 1.340e+08 "2018q3"  -16000000
    21460 "Q4-2018" 1 "stb" "b" 1.072e+08 "2018q4"  -26800000
    20957 "Q2-2017" 1 "su " "b"  54288512 "2017q2"   54300000
    21017 "Q3-2017" 1 "su " "b"  32000000 "2017q3"  -22300000
    21620 "Q1-2019" 1 "su " "b"  12420000 "2019q1"  -19600000
    21412 "Q3-2018" 1 "tm"  "b"  25010000 "2018q3"   25000000
    21536 "Q4-2018" 1 "tm"  "b"  54000000 "2018q4"  279000000
    end
    format %tddd-Mon-YY date
    Last edited by Duncan Mphande; 14 Nov 2022, 07:58.
Working...
X