I am trying to create a figure showing the slope of a line and testing whether the slope is negative or not. However, for some p-values (in the example below, for one of the three graphs), it returns many more digits than the three I specified in my code. Why could this be? Thank you!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year float a int b 2005 1 15 2006 1 15 2007 1 21 2008 1 20 2009 1 26 2010 1 32 2011 1 37 2012 1 42 2013 1 48 2014 1 60 2015 1 57 2016 1 86 2017 1 77 2018 1 66 2019 1 61 2020 1 82 2021 1 101 2007 2 21 2008 2 13 2009 2 28 2010 2 38 2011 2 47 2012 2 33 2013 2 39 2014 2 48 2015 2 47 2016 2 47 2017 2 33 2018 2 29 2019 2 24 2020 2 26 2021 2 29 2008 3 0 2009 3 1 2010 3 1 2011 3 2 2012 3 6 2013 3 4 2014 3 5 2015 3 1 2016 3 5 2017 3 3 2018 3 6 2019 3 4 2020 3 2 2021 3 1 end
Code:
forvalues id = 1/3 { sum year if a ==`id' local minyear`id' = r(min) sum b if a ==`id' local maxcite`id' = r(max) reg b year if a ==`id' scalar scalar_slope`id' = round(_b[year],.01) local slope`id' = scalar_slope`id' local t = _b[year]/_se[year] scalar scalar_p`id' = round(2*ttail(e(df_r),abs(`t')),0.001) local p`id' = scalar_p`id' twoway scatter b year if a ==`id' , msize(vsmall) /// || lfit b year if a ==`id' /// , text(0 2021 "Slope = `slope`id'', p-value = `p`id''" /// , size(vsmall) place(nw) just(right)) /// xtitle("") xlabel(`minyear`id'' 2021, labsize(small)) /// ylabel(0 `maxcite`id'', labsize(small)) /// name(scatter`id', replace) nodraw } grc1leg2 scatter1 scatter2 scatter3 /// , labsize(tiny ) lrows(1) symxsize(.5cm) symysize(.1cm)
Comment