As your surmise, you have get
Stata to stop thinking it's
dealing with a number. Try
reg y x
matrix coefs=e(b)
local beta0hat "`: di 3.2f `=coefs[1,1]''"
local beta1hat "`: di 3.2f `=coefs[1,2]''"
twoway lfit y x, title("fitted line: y = `beta0hat' + `beta1hat' * x")
Nick
[email protected]
Reardon, Sean F.
> i want to fit and draw a regression line and label the line,
> like this:
>
> reg y x
> matrix coefs=e(b)
> loc beta1hat=coefs[1,1]
> loc beta0hat=coefs[1,2]
>
> lfit y x, title("fitted line: y = `beta0hat' + `beta1hat' * x")
>
> when i do this, i get values for the estimated coefficients displayed
> with far more precision than i want. so i want to display
> only, say, 2
> digits after the decimal for each macro. i wasn't able to
> figure out a
> way to apply a display format to a macro, so i tried adding this code
> before the -lfit- command:
>
> loc beta1hat = int(`beta1hat'*100+0.5)/100
> loc beta0hat = int(`beta0hat'*100+0.5)/100
>
> this works most of the time, but sometimes i get a graph that has a
> title like this:
>
> "y = 7.84000000001 + 2.31 * x"
>
> or
>
> "y = 7.83999999999 + 2.31 * x"
>
> i assume that the problem is the rounding doesn't work in
> binary all the
> time. can anyone suggest a way around this? (obviously if i were
> making a single graph, i could put the coefficients in the title by
> hand, but this code is part of a larger program, so i'd like it
> automated.)
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/