Quantcast
Channel: Statalist
Viewing all 72914 articles
Browse latest View live

Getting the current and future 1, 3, 6 month returns

$
0
0
Hello.
I am working on a finance thesis. I want to create current month returns from daily stock prices. Futhermore, I need to get 3 month returns including current month. If the current month is Feb 2016, When I am looking at the 3 month returns, I am using returns from Feb, March, Apr of 2016. For example, Feb, Mar, Apr month returns were 10%, 20% and -10%. 3 months future return of Feb 2016 should be 1.1*1.2*0.9-1=1.188-1. Or, the beginning price of Feb is 100 and the ending price of Apr is 110. The 3 month future return of Feb is= (110-100) / 100 = 10%
I want to have1, 3, and 6 month future returns.

I have thousands of firms daily prices and I already calculated past month returns. I have added my code and my dataex below.
Permno is firm code, date is date, prc is price of stock, ret is daily returns.
Please let me know how I can code my idea. Thank you.


// CALCULATE MONTHLY DATE
gen int mdate = mofd(date)
format mdate %tm
foreach lag of numlist 1 3 6 {
sort permno mdate date
rangestat (first) prc (sd) volatility_`lag' = prc, by(permno) interval(mdate -`lag' -1)
by permno mdate (date): gen ret_`lag' = prc[1]/prc_first - 1
drop prc_first
}


----------------------- copy starting from the next line -----------------------

Code:
* Example generated by -dataex-. To install: ssc install dataex

clear

input double permno long date double(shrcd exchcd prc ret) int mdate double volatility_1 float ret_1 double volatility_3 float ret_3 double volatility_6 float ret_6

10001 20457 11 2 7.519999980926514   .009395996108651161 672                  .           .                  .          .                  .          .

10001 20458 11 2 7.420000076293945  -.013297859579324722 672                  .           .                  .          .                  .          .

10001 20459 11 2  7.53000020980835   .014824816025793552 672                  .           .                  .          .                  .          .

10001 20460 11 2 7.639999866485596   .014608187600970268 672                  .           .                  .          .                  .          .

10001 20461 11 2 7.789999961853027   .019633520394563675 672                  .           .                  .          .                  .          .

10001 20464 11 2   8.0600004196167    .03465987741947174 672                  .           .                  .          .                  .          .

10001 20465 11 2              8.25   .023573147132992744 672                  .           .                  .          .                  .          .

10001 20466 11 2              8.25                     0 672                  .           .                  .          .                  .          .

10001 20467 11 2 8.130000114440918  -.014545440673828125 672                  .           .                  .          .                  .          .

10001 20468 11 2 7.989999771118164  -.017220214009284973 672                  .           .                  .          .                  .          .

10001 20472 11 2 8.119999885559082     .0162703525274992 672                  .           .                  .          .                  .          .

10001 20473 11 2 8.079999923706055  -.004926103632897139 672                  .           .                  .          .                  .          .

10001 20474 11 2 8.100000381469727  .0024753042962402105 672                  .           .                  .          .                  .          .

10001 20475 11 2 8.220000267028809   .014814799651503563 672                  .           .                  .          .                  .          .

10001 20478 11 2                 8  -.026764022186398506 672                  .           .                  .          .                  .          .

10001 20479 11 2 8.100000381469727    .01250004768371582 672                  .           .                  .          .                  .          .

10001 20480 11 2 8.199999809265137    .01234560739248991 672                  .           .                  .          .                  .          .

10001 20481 11 2 8.199999809265137                     0 672                  .           .                  .          .                  .          .

10001 20482 11 2 8.319999694824219   .014634132385253906 672                  .           .                  .          .                  .          .

10001 20485 11 2 8.420000076293945    .01201927661895752 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20486 11 2 8.489899635314941   .008301610127091408 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20487 11 2 8.260000228881836   -.02707916684448719 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20488 11 2                 8   -.03147702291607857 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20489 11 2  8.34000015258789    .04250001907348633 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20492 11 2 8.630000114440918   .034772176295518875 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20493 11 2 8.210000038146973   -.04866744577884674 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20494 11 2 8.300000190734863   .010962259955704212 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20495 11 2 8.050000190734863  -.030120480805635452 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20496 11 2 8.300000190734863    .03105589933693409 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20500 11 2              8.25  -.006024119444191456 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20501 11 2 8.199999809265137  -.006060629151761532 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20502 11 2 8.100000381469727  -.012195052579045296 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20503 11 2 7.900000095367432  -.024691391736268997 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20506 11 2 7.860000133514404  -.005063286051154137 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20507 11 2 7.940000057220459    .01017810683697462 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20508 11 2 7.880000114440918  -.007556668017059565 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20509 11 2 7.940000057220459  .0076142060570418835 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20510 11 2 7.840000152587891  -.012594446539878845 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20513 11 2 7.860000133514404   .002551018027588725 673 .27671314614485903   .11968087 .27671314614485903  .11968087 .27671314614485903  .11968087

10001 20514 11 2 8.300000190734863     .0559796504676342 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20515 11 2  8.15999984741211  -.016867510974407196 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20516 11 2 8.199999809265137  .0049019563011825085 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20517 11 2 8.199999809265137                     0 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20520 11 2   8.1899995803833  -.001219540135934949 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20521 11 2 8.079999923706055  -.013430972583591938 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20522 11 2 8.029999732971191  -.006188142579048872 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20523 11 2 8.119999885559082   .011207989417016506 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20524 11 2                 8  -.014778311364352703 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20527 11 2 7.980000019073486  -.002499997615814209 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20528 11 2 7.900000095367432  -.010025053285062313 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20529 11 2 8.069999694824219    .02151893638074398 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20530 11 2 8.119999885559082  .0061958106234669685 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20531 11 2 8.199999809265137   .009852207265794277 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20534 11 2 8.199999809265137                     0 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20535 11 2 8.199999809265137                     0 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20536 11 2 8.239999771118164   .004878044128417969 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20537 11 2 8.079999923706055  -.019417457282543182 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20541 11 2 7.900000095367432   -.02227720618247986 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20542 11 2 7.889999866485596 -.0012658517807722092 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20543 11 2 7.889999866485596                     0 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20544 11 2 7.809999942779541  -.010139407590031624 674  .2349002451136125 -.014251768  .2628324674888714  .10372343  .2628324674888714  .10372343

10001 20545 11 2 7.800000190734863 -.0012803779682144523 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20548 11 2 7.769999980926514 -.0038461806252598763 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20549 11 2 7.230000019073486   -.06949806213378906 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20550 11 2 7.079999923706055  -.020746901631355286 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20551 11 2 7.369999885559082    .04096044600009918 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20552 11 2 7.579999923706055    .02849389985203743 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20555 11 2 7.769999980926514   .025065971538424492 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20556 11 2 7.869999885559082   .012870000675320625 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20557 11 2 7.800000190734863  .0006353631615638733 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20558 11 2 7.599999904632568    -.0256410613656044 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20559 11 2 7.449999809265137   -.01973685435950756 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20562 11 2  7.21999979019165  -.030872486531734467 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20563 11 2 7.309999942779541   .012465395033359528 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20564 11 2 7.179999828338623   -.01778387278318405 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20565 11 2                 7  -.025069614872336388 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20566 11 2 7.179999828338623   .025714261457324028 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20569 11 2 7.199999809265137   .002785512711852789 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20570 11 2 7.349999904632568   .020833346992731094 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20571 11 2  7.28000020980835  -.009523767977952957 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20572 11 2 7.329999923706055   .006868092343211174 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20573 11 2 7.300000190734863  -.004092732910066843 675 .13742525924620014  -.06024096 .22447660547009565  .03723407 .22447660547009565  .03723407

10001 20576 11 2 6.909999847412109   -.05342470481991768 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20577 11 2 7.039999961853027   .018813330680131912 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20578 11 2 7.039999961853027                     0 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20579 11 2 7.014999866485596 -.0035511499736458063 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20580 11 2 6.880000114440918  -.019244441762566566 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20583 11 2 6.889999866485596  .0014534522779285908 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20584 11 2  6.96999979019165   .011611019261181355 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20585 11 2 7.050000190734863     .0114778196439147 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20586 11 2 7.099999904632568    .00709215784445405 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20587 11 2 7.150000095367432   .007042280398309231 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20590 11 2 7.119999885559082  -.004195833578705788 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20591 11 2 7.139999866485596  .0028089862316846848 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20592 11 2 7.059999942779541  -.011204470880329609 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20593 11 2 6.900000095367432  -.022662868723273277 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20594 11 2 6.880000114440918 -.0028985480312258005 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20597 11 2 6.900000095367432  .0029069739393889904 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20598 11 2 6.900000095367432                     0 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

10001 20599 11 2 6.949999809265137   .007246335037052631 676  .2633846021305704   -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704

end

format %d date

format %tm mdate
------------------ copy up to and including the previous line ------------------




Listed 100 out of 5502429 observations

Use the count() option to list more


loop for dummy variable

$
0
0
I have many data sets in the format such as this one, however most are much longer.
origin is just the country name and year represents the year of an agreement.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9 origin float year
"Australia" 1980
"England"   2000
"USA"       2020
end
This was the code used to generate the results in the format I need them in for analysis, which is fine for this example but for the much larger data sets is there anyway I can use a loop to replace the 0's in the dummies with 1 when the var is a country name and the year is greater or equal to the year of an agreement for that country.

clonevar destination = origin
order origin destination year
fillin year destination origin

gen origin_dummy = 0
gen destination_dummy = 0

replace origin_dummy = 1 if origin == "Australia" & year >= 1980
replace origin_dummy = 1 if origin == "England" & year >= 2000
replace origin_dummy = 1 if origin == "USA" & year >= 2020

replace destination_dummy = 1 if destination == "Australia" & year >= 1980
replace destination_dummy = 1 if destination == "England" & year >= 2000
replace destination_dummy = 1 if destination == "USA" & year >= 2020

drop _fillin

This is the result i'm after for reference

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9(origin destination) float(year origin_dummy destination_dummy)
"Australia" "Australia" 1980 1 1
"England"   "Australia" 1980 0 1
"USA"       "Australia" 1980 0 1
"Australia" "England"   1980 1 0
"England"   "England"   1980 0 0
"USA"       "England"   1980 0 0
"Australia" "USA"       1980 1 0
"England"   "USA"       1980 0 0
"USA"       "USA"       1980 0 0
"Australia" "Australia" 2000 1 1
"England"   "Australia" 2000 1 1
"USA"       "Australia" 2000 0 1
"Australia" "England"   2000 1 1
"England"   "England"   2000 1 1
"USA"       "England"   2000 0 1
"Australia" "USA"       2000 1 0
"England"   "USA"       2000 1 0
"USA"       "USA"       2000 0 0
"Australia" "Australia" 2020 1 1
"England"   "Australia" 2020 1 1
"USA"       "Australia" 2020 1 1
"Australia" "England"   2020 1 1
"England"   "England"   2020 1 1
"USA"       "England"   2020 1 1
"Australia" "USA"       2020 1 1
"England"   "USA"       2020 1 1
"USA"       "USA"       2020 1 1
end

bar chart comparing mean to a constant variable

$
0
0
Dear Stata Community,

I am looking to create a bar graph similar to that below. For simplicity, I will pretend my data is that of the example picture. In my survey, I have five variables that for each respondent, I have collected data on the scale from 1 to 100. From my data I have means that are below the national average, explained in the below table:
Var Mean Nat. Ave
AP 25 100
CF 50 100
CC 35 75
FF 67 75
IM 39 50


In my data set, I have generated variables to represent the national averages
gen APna=100
and so forth...



My goal is to make a bar chart like the one above, where my actual data for each variable is represented as a mean (solid), and its national average is displayed over it as an outline. In my actual data, I do have one variable that whose national average is higher than the mean, so I would need the lines to be in front of the means. I can easily change titles in the graph editor so no need to worry about including titles in the code.

Thank you in advance!

StataSE 15 (64bit)
Windows 10

Multivariate Regression value higher than univariate?

$
0
0
This is a simple question: I have done a small research study where I had a significant (Logistic regression) association with outcome by treatment group. When doing further analysis only one other variable was significant with outcome. Putting the second confounding explanatory variable into the model with the primary treatment variable, my OR actually increased. Usually it is reduced somewhat. Is this a common event? Have we potentially done something wrong with this rather simple model of two covariates? Thanks!

Panel Data model interpretation: Choosing between FE and RE

$
0
0
Hi. I have a long panel, that is my T is 16 and N=8. Where the dependent variable is number of under 5 deaths, and the independent variables are Domestic Govt exp, Number of physicians, Sanitation, Basic Drinking water, Fertility rate, carbon dioxide emission, number of hospital beds. (in that order)


I have the following results:

Fixed Effects model.

Array

Random Effects model:
Array


After running for the FE and the RE model, I see that the random effects model provides me with good results, but the hausman test is significant, hence I should choose FE. Please tell me why this is the case

change in sign and significance of linear term after adding quadratic and cubic terms

$
0
0
Hi all,

I need your comments on change in sign and significance of linear term after adding quadratic and cubic terms. please see details below:

I am using panel data with 681 firms and 9 years each.

DV: In_roa (firm performance)
IV: ff_d (dummy variable, whether firm is family firm or not, if family then 1)
IV: stdfo_own (shares held by an investment company in a firm, values ranges from 0 to 100, moreover i standardized this variable by egen stdvar=std(var) in order to get standardized coefficients ) ----- quadratic and cubic terms of this variable are also used later.

rest four variables are control variables

DV and all control variables are log transformed

i also add interaction terms of both IVs

When i ran xtreg ,fe only with linear terms and their respective interaction. The results are following

Code:
. xtreg ln_roa ln_age ln_assets ln_leverage ln_ebitda stdfo_own i.ff_d c.stdfo_own#i.ff_d i.year,fe

Fixed-effects (within) regression               Number of obs     =      2,619
Group variable: sr                              Number of groups  =        435

R-sq:                                           Obs per group:
     within  = 0.3449                                         min =          1
     between = 0.0702                                         avg =        6.0
     overall = 0.0961                                         max =          9

                                                F(15,2169)        =      76.14
corr(u_i, Xb)  = -0.9166                        Prob > F          =     0.0000

----------------------------------------------------------------------------------
          ln_roa |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------------+----------------------------------------------------------------
          ln_age |  -.2425169   .1151951    -2.11   0.035    -.4684213   -.0166125
       ln_assets |   .0968887   .0733825     1.32   0.187    -.0470188    .2407961
     ln_leverage |   -.090931   .0229502    -3.96   0.000    -.1359377   -.0459243
       ln_ebitda |   1.143277   .0353174    32.37   0.000     1.074017    1.212536
       stdfo_own |   .1853135   .0686506     2.70   0.007     .0506857    .3199414
          1.ff_d |   1.106262   .4312164     2.57   0.010     .2606212    1.951902
                 |
ff_d#c.stdfo_own |
              1  |  -.3014559   .1265948    -2.38   0.017    -.5497158   -.0531961
                 |
            year |
           2008  |  -.1011256   .0543446    -1.86   0.063    -.2076986    .0054474
           2009  |  -.1452684   .0588673    -2.47   0.014    -.2607106   -.0298262
           2010  |  -.1071921   .0573892    -1.87   0.062    -.2197355    .0053514
           2011  |  -.0159812   .0603661    -0.26   0.791    -.1343627    .1024002
           2012  |   -.021513   .0640318    -0.34   0.737    -.1470832    .1040571
           2013  |  -.0861119   .0674674    -1.28   0.202    -.2184194    .0461957
           2014  |  -.0374172   .0699141    -0.54   0.593    -.1745228    .0996884
           2015  |  -.0255822   .0741488    -0.35   0.730    -.1709924     .119828
                 |
           _cons |   1.423105   .9439093     1.51   0.132    -.4279559    3.274166
-----------------+----------------------------------------------------------------
         sigma_u |  2.2670211
         sigma_e |  .64303764
             rho |  .92553463   (fraction of variance due to u_i)
----------------------------------------------------------------------------------
F test that all u_i=0: F(434, 2169) = 10.38                  Prob > F = 0.0000
but when i add quadratic and cubic terms with their respective interaction terms, change of sign of main linear effect of Stdfo_own arise and main variable and its interaction term also goes insignificant. Please see below:

Code:
. xtreg ln_roa ln_age ln_assets ln_leverage ln_ebitda stdfo_own i.ff_d c.stdfo_own#i.ff_d c.stdfo_own#c.stdfo_o
> wn c.stdfo_own#c.stdfo_own#c.stdfo_own i.ff_d#c.stdfo_own#c.stdfo_own i.ff_d#c.stdfo_own#c.stdfo_own#c.stdfo_
> own i.year,fe

Fixed-effects (within) regression               Number of obs     =      2,619
Group variable: sr                              Number of groups  =        435

R-sq:                                           Obs per group:
     within  = 0.3525                                         min =          1
     between = 0.0702                                         avg =        6.0
     overall = 0.0972                                         max =          9

                                                F(19,2165)        =      62.04
corr(u_i, Xb)  = -0.9157                        Prob > F          =     0.0000

----------------------------------------------------------------------------------------------------------
                                  ln_roa |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------------------------------------+----------------------------------------------------------------
                                  ln_age |  -.2487596    .114643    -2.17   0.030    -.4735815   -.0239377
                               ln_assets |   .1082457   .0732253     1.48   0.139    -.0353535    .2518448
                             ln_leverage |  -.0875726   .0228485    -3.83   0.000    -.1323799   -.0427653
                               ln_ebitda |   1.147255   .0351986    32.59   0.000     1.078229    1.216282
                               stdfo_own |  -.4299763   .2723444    -1.58   0.115    -.9640601    .1041074
                                  1.ff_d |   1.385639   .5345586     2.59   0.010     .3373372    2.433941
                                         |
                        ff_d#c.stdfo_own |
                                      1  |   .1154103   .4098834     0.28   0.778    -.6883959    .9192164
                                         |
                 c.stdfo_own#c.stdfo_own |   1.829437   .3914211     4.67   0.000     1.061837    2.597038
                                         |
     c.stdfo_own#c.stdfo_own#c.stdfo_own |   -.548248   .1106208    -4.96   0.000    -.7651821    -.331314
                                         |
            ff_d#c.stdfo_own#c.stdfo_own |
                                      1  |   -1.62318   .5700911    -2.85   0.004    -2.741162   -.5051965
                                         |
ff_d#c.stdfo_own#c.stdfo_own#c.stdfo_own |
                                      1  |   .5078677   .1566739     3.24   0.001     .2006207    .8151146
                                         |
                                    year |
                                   2008  |  -.0976755   .0541075    -1.81   0.071    -.2037836    .0084325
                                   2009  |  -.1358211   .0586226    -2.32   0.021    -.2507835   -.0208587
                                   2010  |  -.0975943   .0571462    -1.71   0.088    -.2096614    .0144728
                                   2011  |    .000361   .0602345     0.01   0.995    -.1177626    .1184846
                                   2012  |  -.0069673   .0638666    -0.11   0.913    -.1322135     .118279
                                   2013  |   -.076881   .0672857    -1.14   0.253    -.2088323    .0550702
                                   2014  |  -.0218242   .0697872    -0.31   0.755    -.1586811    .1150327
                                   2015  |  -.0140085   .0739652    -0.19   0.850    -.1590588    .1310417
                                         |
                                   _cons |   .8776022   .9563418     0.92   0.359    -.9978418    2.753046
-----------------------------------------+----------------------------------------------------------------
                                 sigma_u |  2.2607953
                                 sigma_e |  .63990051
                                     rho |  .92582914   (fraction of variance due to u_i)
----------------------------------------------------------------------------------------------------------
F test that all u_i=0: F(434, 2165) = 10.46                  Prob > F = 0.0000

.
it would be great if anyone can explain why does this change happens and what does it mean.
best regards,

A question from an absolute beginner: hospitalization data

$
0
0
Hi everybody.
I have a set of hospital discharge records (time window 2001-2016) with the main diagnosis for a cohort made up by about 5,000 former petrochemical workers. It is a follow up of the cohort studied years ago with, of course, a shorter time window (2001-2006).
In the previous occasion, Hospital Discharge Odds Ratios (HDORs) by job category (reference White collars) were calculated.
Does any of forum participants have a suggestion for the analysis to perform now?
I am wondering whether to use the same approach, or to widen it, mainly for the length of the period.
Thank's a lot for help.

Flexible Regression Specification for Panel Data

$
0
0
Dear Stata community,

I am currently looking to estimate a somewhat complex regression model to analyze the market value of banks. The model can be found in Calomiris and Nissim (2007), and is pictured below.
or every bank I have data over multiple quarters. Further, as some variables are year on year growth variables in a quarterly data set I expect auto-correlation issues and would like to have the variables follow an AR(q) process. Because of this I thought about using -xtregar-, but I am not sure how to incorporate the FV variables with no coefficient (or a coefficient set ==1) and the brackets. The brackets are needed as the w variables indicate the amount of capital invested in the activity relative to total capital, and the calculation in the brackets yields the value generated for every dollar invested in an activity.

Does anyone have any suggestions?
Array
parameters as alpha, beta, delta, gamma, rho, lambda as well as v(Ltd), v(otherasset) and v(otherliab) are parameters to be estimated.

Combining Cox Proportional Hazards model and Difference-in-Differences

$
0
0
Dear All,

My question concerns whether it is possible to combine a Cox proportional hazards model with a difference-in-differences approach and if so, how that would be implemented in Stata. I am very new to Cox proportional hazard models so please excuse my lack of knowledge. I truly appreciate any help.

My case is the following: I have a panel of firms covering a large range of years. In some year several industries were affected by an increase in tariffs (treatment group) whereas others were not (control group). Crucially, I have data for years both before and after this tariff change occurred. What I am interested in is how this policy change affected the probability of firm survival. Naturally, I would fit a DID model since I have before and after data as well as a treatment and control group. However, I am interested in whether the increase in tariffs decreased the likelihood of failure. As well, my data is right-censored. Thus, from reading the literature I got the sense that I should combine the DID approach with a Cox model. However, I am unsure how to do this.

Specifically, I am wondering

1) How should I structure my data? At this moment I have one observation for each firm and year it was in existence. However, for Cox models the data usually seems to be organized in a way so that each firm has only one line.

2) Is there a straightforward way to implement a DID analysis using the Cox model? How would that be coded?

Again, thank you very much for considering my case and I appreciate any help!

All the best
Leon

Matching observations across years for same id

$
0
0
Hi Forum,

I am struggling with something very silly but would be very helpful if someone could help me out.
I have an id variable which identifies the product and the size (e.g Coca Cola 600 ml)

Since my analysis is to evaluate a policy impact, I want to make sure that for the same product I have observations for both years.
However, there are some products that I have N observations for one year and 0 for the other, which could bias my research.

I am trying to drop those products who do not have observations for both years so I can compare the changes between them

Any suggestions?

Many thanks!!

Best,

Lena

Test for coefficients of different regressions

$
0
0
Dear All,

I'm working with Fama & MacBeth regressions. My sample is divided in quintiles and I run one regression for each quintile. Below, the code for the first and the last quintile.

regress ex_ret mkt smb hml if tin(1,8199) & port_BTM==1

regress ex_ret mkt smb hml if tin(1,8199) & port_BTM==5

So, I need to know if the difference between the coefficients for the last and the first quintile (for the same variable) are equal to zero.

Does anyone have any idea about how to do this?

Thank you!

Closest date for financial report from event date

$
0
0
Hello forum,
I am running an event study (multiple events per company) and want to map the financial data before and after an event. I have collated the financial report dates and event dates in a single file. For each event date I want to know the closest financial report date both pre and post (if available) in 2 separate columns. I have over 8000 events and 13,000 financial report dates.

id: Company id
date: date (stored in numeric format)
fin data: dummy for if the date pertains to financial report date
event flag: dummy for event date

I want to generate 2 columns 'Pre' and 'Post' which should have closest financial report date (by company) for each event date.

Sample data:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float id long date byte(findata eventflag)
12 37621 1 .
12 37986 1 .
12 38352 1 .
12 38700 . 1
12 38717 1 .
12 39082 1 .
12 39447 1 .
12 39813 1 .
12 39940 . 1
12 40178 1 .
12 40428 . 1
12 40443 . 1
12 40543 1 .
12 40568 . 1
12 40907 . 1
12 40908 1 .
12 41274 1 .
12 41277 . 1
12 41547 . 1
12 41562 . 1
12 41639 1 .
12 42004 1 .
12 42369 1 .
12 42735 1 .
12 43100 1 .
12 43465 1 .
 1 38344 . 1
 1 38573 . 1
 1 38757 . 1
 1 38993 . 1
 1 39063 . 1
 1 39143 . 1
 2 37378 . 1
 2 37524 . 1
 2 37955 1 .
 2 38093 . 1
 2 38321 1 .
 2 38322 . 1
 2 38686 1 .
 2 39051 1 .
 2 39416 1 .
 2 39782 1 .
 2 40147 1 .
 3 38057 . 1
 3 38687 . 1
 3 39122 . 1
 3 40603 . 1
 3 41184 . 1
 3 41459 . 1
 4 37641 . 1
 4 37712 . 1
 4 37876 . 1
 5 40908 1 .
 5 41274 1 .
 5 41486 . 1
 5 41639 1 .
 5 41694 . 1
 5 42004 1 .
 5 42369 1 .
 5 42735 1 .
 5 43100 1 .
 6 37621 1 .
 6 37986 1 .
 6 38352 1 .
 6 38618 . 1
 6 38717 1 .
 6 38810 . 1
 6 38875 . 1
 6 39082 1 .
 6 39183 . 1
 6 39447 1 .
 6 39813 1 .
 6 40178 1 .
 6 40543 1 .
 6 40908 1 .
 6 41274 1 .
 6 41639 1 .
 6 42004 1 .
 6 42369 1 .
 6 42735 1 .
 7 40504 . 1
 7 40835 . 1
 7 41207 . 1
 8 36068 1 .
 8 36891 1 .
 8 37256 1 .
 8 37552 . 1
 8 37621 1 .
 8 37652 . 1
 8 37930 . 1
 8 37945 . 1
 8 37963 . 1
 8 37986 1 .
 8 37991 . 1
 8 38015 . 1
 8 38078 . 1
 8 38125 . 1
 8 38344 . 1
 8 38352 1 .
 8 38717 1 .
end
I can also arrange the data in a different format if required.

Thanks.

Show percent within a category on a bar graph

$
0
0
I am trying to show the percent of a category on a bar graph, when I use the option 'percentage' it shows the percent of the group, where I want the "row" percent of that subgroup (when I leave percentage out, it gives the proportion - which is what I want on the graph but in %)

This code:
Code:
graph bar HIV2, over(Income, relabel(1 "Low & low-middle" 2 "Upper-middle" 3 "High") ///
 label(angle(forty_five))) over(group, relabel(1 "2000-2003" 2 "2004-2006" 3 "2007-2009" 4 "2010-2012" 5 "2013-2015")) ///
  scheme(s2color) ytitle(Proportion) ///
 blabel(bar, format(%4.1f) size(vsmall)) ///
graphregion(fcolor(white)) ///
 asyvars bar(1, fcolor(ebg)) bar(2, fcolor(ebblue)) bar(3, fcolor(edkblue))
gives:
Array

How can I get those proportions as percents without using something like catplot?

New version of xdir on SSC

$
0
0
Thanks as always to Kit Baum, a new version of the xdir package is now available for download from SSC. In Stata, use the ssc command to do this, or adoupdate if you already have an old version of xdir.

The xdir package is described as below on my website. The new version adds an option plocal(local_macro_name), specifying that a local macro will be created in the calling segment, containing a list of the files specified complete with a prefixed directory path. This can be very useful if the user wants to concatenate the specified files into the memory using the append command.

I am hoping that this will be the last version of xdir in Stata Version 10, before I update it to a Stata Version 16 version, using data frames. (I plan to continue to distribute the old version on my website, for users of Stata Versions 10-15.)

Best wishes

Roger


-------------------------------------------------------------------------------
package xdir from http://www.rogernewsonresources.org.uk/stata10
-------------------------------------------------------------------------------

TITLE
xdir: Create a resultsset with 1 observation per file in a directory

DESCRIPTION/AUTHOR(S)
xdir is an extended version of dir, or of the extended macro
function dir. It creates an output dataset (or resultsset), with 1
observation for each file in a user-specified directory conforming
to a user-specified pattern, and belonging to a user-specified file
type, and data on the file name and the directory name. This
dataset may be listed using the list() option and/or saved to a file
using the saving() option and/or written to the memory using the
norestore or fast option, overwriting any existing dataset.
Alternatively (or additionally), a list of the file names may be
saved in a local macro.

Author: Roger Newson
Distribution-Date: 05august2019
Stata-Version: 10

INSTALLATION FILES (click here to install)
xdir.ado
xdir.sthlp
-------------------------------------------------------------------------------
(click here to return to the previous screen)


Using contrast post logistic to assess linear trend - response to a reviewer

$
0
0
Hello

I am assessing the relationship between a binary outcome variable and a 4-category variable (cat_boy_ful) while controlling for potential co-variates/confounders using logistic:

logistic cancer i.cat_boy_ful refage i.race_c4 i.ocmos_c i.num_full_c

and then assessing if there is a linear trend using contrast

contrast p.cat_boy_ful, noeffects

The ORs from the logistic model are:

------------------------------------------------------------------------------
cancer | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
cat_boy_ful |
1 | 1.158866 .1314434 1.30 0.194 .9278688 1.447372
2 | 1.485356 .2044201 2.87 0.004 1.134189 1.945253
3+ | 1.374283 .2647452 1.65 0.099 .9421038 2.00472

and the results of contrast are:
------------------------------------------------
| df chi2 P>chi2
-------------+----------------------------------
cat_boy_ful |
(linear) | 1 3.89 0.0487
(quadratic) | 1 1.27 0.2590
(cubic) | 1 1.49 0.2224
Joint | 3 8.73 0.0331
------------------------------------------------

indicating a significant linear trend at the cutoff of 0.05.

A reviewer of the paper questioned this because the OR for the 3+ category is less than that of the 2 category (1.37 vs 1.49).

Can someone help me understand and respond to this reviewer?

Thank you!

Dropping stocks below 5th percentile

$
0
0
Dear Statalists,

I would like to drop the stocks whose market value (MV) is below 5th percentile of all stocks in each month and would like to ask for the assistance.
Thank you in advance!

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 dscd str10 MV str8 var4 float(DATE month year)
"131879" "1858,53" "19800229"  7364  2 1980
"131879" "2044,56" "19800331"  7395  3 1980
"131879" "1844,64" "19800430"  7425  4 1980
"131879" "1670,26" "19800530"  7455  5 1980
"131879" "1644,39" "19800630"  7486  6 1980
"131879" "1642,57" "19800731"  7517  7 1980
"131879" "1586,6"  "19800829"  7546  8 1980
"131879" "1763,44" "19800930"  7578  9 1980
"131879" "1546,18" "19801031"  7609 10 1980
"131879" "1563,4"  "19801128"  7637 11 1980
"131879" "1242,44" "19801231"  7670 12 1980
"131879" "1290,62" "19810130"  7700  1 1981
"131879" "1353,73" "19810227"  7728  2 1981
"131879" "1289,06" "19810331"  7760  3 1981
"131879" "602,85"  "19810430"  7790  4 1981
"131879" "670,47"  "19810529"  7819  5 1981
"131879" "779,26"  "19810630"  7851  6 1981
"131879" "717,34"  "19810731"  7882  7 1981
"131879" "668,54"  "19810831"  7913  8 1981
"131879" "685,68"  "19810930"  7943  9 1981
"131879" "759,76"  "19811030"  7973 10 1981
"131879" "1014,62" "19811130"  8004 11 1981
"131879" "1156,44" "19811231"  8035 12 1981
"131879" "1169,23" "19820129"  8064  1 1982
"131879" "1468,25" "19820226"  8092  2 1982
"131879" "1478,28" "19820331"  8125  3 1982
"131879" "1880,86" "19820430"  8155  4 1982
"131879" "1707,42" "19820528"  8183  5 1982
"131879" "1736,22" "19820630"  8216  6 1982
"131879" "1733,99" "19820730"  8246  7 1982
"131879" "1587,08" "19820831"  8278  8 1982
"131879" "1699,51" "19820930"  8308  9 1982
"131879" "1681,22" "19821029"  8337 10 1982
"131879" "1645,75" "19821130"  8369 11 1982
"131879" "1743,25" "19821231"  8400 12 1982
"131879" "2287,1"  "19830131"  8431  1 1983
"131879" "2230,49" "19830228"  8459  2 1983
"131879" "2576,67" "19830331"  8490  3 1983
"131879" "2858,24" "19830429"  8519  4 1983
"131879" "3050,69" "19830531"  8551  5 1983
"131879" "3052,93" "19830630"  8581  6 1983
"131879" "2731,86" "19830729"  8610  7 1983
"131879" "2524,69" "19830831"  8643  8 1983
"131879" "2503,48" "19830930"  8673  9 1983
"131879" "2300,83" "19831031"  8704 10 1983
"131879" "1992,86" "19831130"  8734 11 1983
"131879" "2319,52" "19831230"  8764 12 1983
"131879" "2102,17" "19840131"  8796  1 1984
"131879" "1640,99" "19840229"  8825  2 1984
"131879" "1227,67" "19840330"  8855  3 1984
"131879" "1404,35" "19840430"  8886  4 1984
"131879" "1292,17" "19840531"  8917  5 1984
"131879" "1280,6"  "19840629"  8946  6 1984
"131879" "1547,26" "19840731"  8978  7 1984
"131879" "1332,18" "19840831"  9009  8 1984
"131879" "1365,85" "19840928"  9037  9 1984
"131879" "1090,49" "19841031"  9070 10 1984
"131879" "1030,51" "19841130"  9100 11 1984
"131879" "1108,18" "19841231"  9131 12 1984
"131879" "1032,98" "19850131"  9162  1 1985
"131879" "1031,02" "19850228"  9190  2 1985
"131879" "1100,84" "19850329"  9219  3 1985
"131879" "1119,75" "19850430"  9251  4 1985
"131879" "1204,75" "19850531"  9282  5 1985
"131879" "1435,58" "19850628"  9310  6 1985
"131879" "1615,83" "19850731"  9343  7 1985
"131879" "1386,97" "19850830"  9373  8 1985
"131879" "1440,61" "19850930"  9404  9 1985
"131879" "1635,6"  "19851031"  9435 10 1985
"131879" "1395,72" "19851129"  9464 11 1985
"131879" "1195,82" "19851231"  9496 12 1985
"131879" "1377,02" "19860131"  9527  1 1986
"131879" "1685,52" "19860228"  9555  2 1986
"131879" "2179,01" "19860331"  9586  3 1986
"131879" "2285,13" "19860430"  9616  4 1986
"131879" "2482,51" "19860530"  9646  5 1986
"131879" "1861,24" "19860630"  9677  6 1986
"131879" "1596,95" "19860731"  9708  7 1986
"131879" "1738,22" "19860829"  9737  8 1986
"131879" "2069,89" "19860930"  9769  9 1986
"131879" "2164,9"  "19861031"  9800 10 1986
"131879" "2475,48" "19861128"  9828 11 1986
"131879" "2689,39" "19861231"  9861 12 1986
"131879" "3043,45" "19870130"  9891  1 1987
"131879" "3095,35" "19870227"  9919  2 1987
"131879" "3833,58" "19870331"  9951  3 1987
"131879" "3939,12" "19870430"  9981  4 1987
"131879" "3351,86" "19870529" 10010  5 1987
"131879" "3352,8"  "19870630" 10042  6 1987
"131879" "3247,31" "19870731" 10073  7 1987
"131879" "3938,7"  "19870831" 10104  8 1987
"131879" "4666,43" "19870930" 10134  9 1987
"131879" "4242,82" "19871030" 10164 10 1987
"131879" "3712,53" "19871130" 10195 11 1987
"131879" "3783,5"  "19871231" 10226 12 1987
"131879" "3626,74" "19880129" 10255  1 1988
"131879" "3747,59" "19880229" 10286  2 1988
"131879" "3102,95" "19880331" 10317  3 1988
"131879" "4990,3"  "19880429" 10346  4 1988
"131879" "5092,14" "19880531" 10378  5 1988
end
------------------ copy up to and including the previous line ------------------

WHEN to delete missing/negative values?

$
0
0
Hello,

I was wondering when it is best to clean the data (i.e. delete missing or negative values) when performing different types of regression analysis?
If I want to first perform a linear regression, and afterwards a multiple regression; should I delete all the negative values of the variables (i.e. keep only VAR>=0) I want to use at the beginning/ before running both regressions, or should I only delete the missing data which will be used for THE particular regression?

I would think that the first option is better, since the same amount of observations will remain for each type of regression.
Otherwise, the linear regression could be based on for instance 20,000 observations, and the multiple regression based on 14,000 observations...
Can someone confirm this?

Thanks in advance!

Scatter plot

$
0
0
how to create a scatter plot of two categorical variables by assigning one to shape and other to color. in this example

Multiple imputation on continuous outcome variable

$
0
0
Hello,

I have been running regression analysis on CFU outcomes where there is a lower limits of detection (3 log10). I have total of 134 observations. Among those I have 23 observations that were zero ( but not true zero they are under detection limit) and 2 other missing observations. I have treatment and clustered pen effects that I would like to measure effects of treatment on CFU using linear regression with cluster of pen effects.

Basically my goal is to impute those observations between zero and lower limits of detection. Here are the steps I followed:

mi set wide
mi register regular treatment pen
mi register imputed cfu
gen ulimplog10=3
gen llimplog10=0
replace llimp = cfu if cfu> 0 & cfu< 99999999999
replace ulimplog10 = cfu if cfu> 0 & cfu< 99999999999

mi impute intreg cfuimputed b(1).treatment pen, add(20) rseed(1234) ll(llimplog10) ul(ulimplog10)

mi estimate: mixed cfuimputed ib(1).treatment|| pen_id:

mimrgns treatment, cmdmargins
marginsplot, xdimension(trteatment) recast(bar)

The model converged nicely. I wonder if this is a valid approach?

specially adding treatment and pen during imputation process?

Many thanks in advance

Gizem



Merge baseline and follow-up datasets

$
0
0
I have baseline data on patients and another dataset that has follow up data on the same patients. I tried to merge but was not successful. Is there a way to merge these datasets?
Here are the first nine rows from each dataset:

Baseline dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long maskid float visit byte(statin aspirin intensive) float pctrw byte censor_po int sbp_base
104786 1 1 1 0  7.799415 1 106
102048 1 1 0 1  9.438554 1 131
104783 1 1 0 0 3.9590964 1 145
101412 1 1 1 0 4.6846213 1 113
108992 1 1 0 1  8.814975 1 158
102651 1 1 0 1  5.018142 1 136
101435 1 1 0 1  6.218245 1 132
103047 1 1 0 1 2.2991269 1 136
106781 1 1 1 0  7.042958 1 108
end
label values intensive intSstdlabel
label def intSstdlabel 0 "standard", modify
label def intSstdlabel 1 "intensive", modify

Follow-up dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long maskid byte(visit total_mmse total_dsc) int stroop float ravlt
100006 1 30 68 34  9.066667
100014 1 30 66 14 4.0666666
100020 1 30 80 16      11.6
100024 1 30 69 22       9.2
100026 1 28 69 21  9.666667
100030 1 29 74 20  8.466666
100032 1 30 57 10      12.4
100037 1 30 60 13       7.4
100046 1 29 40 32  7.133333
end














Viewing all 72914 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>