Announcement

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

  • How to code double or tripple summation of variables in Stata

    Please help out with how to code and evaluate the double summation of variables. I could not locate any previous case, in fact one similar, posted on 30 April 2019 by a user here remains unresolved. I will be grateful for your kind assistance
    .
    Am evaluating the equation ∑_from k=1 to K [ ∑_from n=1 to Nk,t ∑_from (m=1,m≠1) to Nk,t-1 (Dn,k,t, - meanRawbart ) (Dm,k,t-1 - meanRawbarLt-1 )/Nk,t Nk,t-1 ]

    whose image is below (the image is not appearing, so i have posted a separate attachment)



    b=




    The variable names are as below
    K =
    Nk,t = Number of institutions trading stock k in quarter t
    Nk,t-1 = Number of institutions trading stock k in quarter t -1

    Dn,k,t = Dummy variable that equals one (zero) if trader n is a buyer(seller) of security k in quarter t

    meanRawbart = mean of change in demand during quarter t

    Dm,k,t-1 = Dummy variable that equals one (zero) if trader m (m ≠ n) is a buyer(seller) of security k in quarter t-1

    meanRawbarLt-1 = mean of change in demand during quarter t-1


    my sample data is as below

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(date investor_id) str6 qdate byte(K Dnkt Dnkt_1 Dmkt1) double(meanRawbar meanRawbarL) byte(Nkt Nkt_1)
    22159 108 "2020q3" 4 1 0 0       .8      .75 2  2
    22097 108 "2020q3" 4 1 1 1       .8      .75 1  1
    22159  19 "2020q3" 4 1 1 1       .8      .75 2  2
    22097  15 "2020q3" 4 0 1 1       .8      .75 1  4
    22159  15 "2020q3" 4 1 1 1       .8      .75 1  3
    21934  19 "2020q1" 6 0 1 1       .6 .5714286 5  7
    21930  58 "2020q1" 6 0 1 1       .6 .5714286 5 18
    21930 108 "2020q1" 6 1 1 1       .6 .5714286 4  7
    21930  74 "2020q1" 6 0 0 0       .6 .5714286 4 14
    21937 108 "2020q1" 6 1 0 0       .6 .5714286 1  1
    21930 108 "2020q1" 6 0 1 1       .6 .5714286 2 11
    21935  15 "2020q1" 6 1 1 1       .6 .5714286 4  7
    21936  19 "2020q1" 6 1 0 0       .6 .5714286 1  9
    21927 108 "2020q1" 6 0 1 1       .6 .5714286 5  7
    21930  71 "2020q1" 6 0 1 1       .6 .5714286 5  7
    21945  15 "2020q1" 6 1 1 1       .6 .5714286 5  7
    21935  19 "2020q1" 6 1 0 0       .6 .5714286 2 11
    21935 108 "2020q1" 6 1 1 1       .6 .5714286 2  3
    21935  15 "2020q1" 6 1 0 0       .6 .5714286 2  3
    21930  58 "2020q1" 6 1 0 0       .6 .5714286 4 11
    17268  46 "2007q2" 8 1 1 1 .6470588     .625 3  4
    17283  49 "2007q2" 8 0 . . .6470588     .625 1  .
    17342  45 "2007q2" 8 1 0 0 .6470588     .625 2  6
    17344 120 "2007q2" 8 1 . . .6470588     .625 1  .
    17261  46 "2007q2" 8 1 . . .6470588     .625 5  .
    17290 100 "2007q2" 8 0 . . .6470588     .625 5  .
    17332  73 "2007q2" 8 1 . . .6470588     .625 5  .
    17261 108 "2007q2" 8 1 0 0 .6470588     .625 2  6
    17295  14 "2007q2" 8 0 1 1 .6470588     .625 3  4
    17309  87 "2007q2" 8 1 0 0 .6470588     .625 3  4
    end
    format %tddd-Mon-YY date
    The variable qdate is generated from variable date and is formatted. I use the following code to format it
    Code:
    gen qdate= qofd(date)
    format qdate %tq
    i will be grateful for kind feedback
    Last edited by Duncan Mphande; 08 Dec 2022, 08:26.

  • #2
    The image of the equation has not appeared, however i have attached it below
    Attached Files

    Comment

    Working...
    X