Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: changing display format of macro contents


From   "Reardon, Sean F." <[email protected]>
To   <[email protected]>
Subject   st: changing display format of macro contents
Date   Tue, 18 Jan 2005 11:08:04 -0800

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.)
 
thanks,
sean.
_____________________________
 
please note new contact information:
_____________________________
 
sean f. reardon
associate professor of education and (by courtesy) sociology
school of education
485 lasuen mall, #315
stanford university
stanford, ca 94305-3096
650.736.8517 (office phone)
650.725.7412 (office fax)
[email protected]
_____________________________
 



*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index