Please help me standardize a variable ( i want a value MINUS mean /SD) a variable named rawbuy which i generate based on grouping data into quarters.
Here is my code that i used to generate qdate
and here is the code that i use to generate the other variables such as n_buying, n_selling Qb and Qs and finally rawbuy. For e.g. n_buying, is count of +, for variable ticker during quarter, variable qdate
i then aggregate for each quarter, the total for all n_buying, for different tickers. same for n_seling. I then compute a ratio [ n_buying/ (n_buying + n_selling)], whihc i call rawbuy. I would like to standardize this rawbuy so that i can directly compare coefficients in my investigation
my sample data looks like this
Here is my code that i used to generate qdate
Code:
gen date3 =date(date,"DMY") format %td date3 format %tddd-Mon-YY date3 gen qdate= qofd(date3) format qdate %tq
Code:
egen id3= group(ticker qdate) sort id3 by id3: egen n_buying = total(q_status == "+") by id3: egen n_selling = total(q_status == "-")
i then aggregate for each quarter, the total for all n_buying, for different tickers. same for n_seling. I then compute a ratio [ n_buying/ (n_buying + n_selling)], whihc i call rawbuy. I would like to standardize this rawbuy so that i can directly compare coefficients in my investigation
Code:
sort id3 by id3 : egen Qb = total(n_buying) by id3 : egen Qs = total(n_selling) by id3 : gen rawbuy = Qb/(Qb +Qs)
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input int date str3 ticker str6 qdate str1 q_status int id3 byte(n_buying n_selling Qb Qs) double rawbuy
17261 "fgm" "2007q2" "+" 27 4 1 20 5 .8
17261 "fgm" "2007q2" "+" 27 4 1 20 5 .8
17261 "lvi" "2007q2" "+" 84 2 0 4 0 1
17266 "nih" "2007q2" "+" 342 2 0 4 0 1
17283 "nmp" "2007q2" "-" 186 0 1 0 1 0
17289 "nih" "2007q2" "+" 342 2 0 4 0 1
17290 "fgm" "2007q2" "-" 27 4 1 20 5 .8
17304 "okm" "2007q2" "-" 393 0 2 0 4 0
17309 "pla" "2007q2" "+" 439 2 1 6 3 .6666667
17329 "okm" "2007q2" "-" 393 0 2 0 4 0
17332 "fgm" "2007q2" "+" 27 4 1 20 5 .8
17342 "lvi" "2007q2" "+" 84 2 0 4 0 1
17342 "nsk" "2007q2" "-" 239 0 1 0 1 0
17344 "nid" "2007q2" "+" 293 1 0 1 0 1
17352 "nsk" "2007q3" "-" 240 1 3 4 12 .25
17358 "nsk" "2007q3" "-" 240 1 3 4 12 .25
17371 "san" "2007q3" "+" 568 1 1 2 2 .5
17378 "nih" "2007q3" "+" 343 3 2 15 10 .6
17381 "fgm" "2007q3" "-" 28 1 5 6 30 .1666667
17381 "okm" "2007q3" "+" 394 2 0 4 0 1
17381 "okm" "2007q3" "+" 394 2 0 4 0 1
17388 "nih" "2007q3" "+" 343 3 2 15 10 .6
17392 "fgm" "2007q3" "+" 28 1 5 6 30 .1666667
17392 "fgm" "2007q3" "-" 28 1 5 6 30 .1666667
17398 "lvi" "2007q3" "-" 85 0 1 0 1 0
17398 "pla" "2007q3" "-" 440 1 2 3 6 .3333333
17406 "nsk" "2007q3" "-" 240 1 3 4 12 .25
17406 "nih" "2007q3" "+" 343 3 2 15 10 .6
17422 "fgm" "2007q3" "-" 28 1 5 6 30 .1666667
17436 "fgm" "2007q3" "-" 28 1 5 6 30 .1666667
end
format %tddd-Mon-YY date
Comment