Here is an example which writes the p-value from a t-test into a text file. The p-value is rounded to the third decimal.
sysuse auto, clear
ttest price, by(fore)
file open myfile using "foo.txt", write replace
file write myfile "price & " %5.3f (r(p)) " \\"
file close myfile
type "foo.txt"
I have specified a 5.3f
format. The first number means that the output will have a width of 5. This width includes the decimal point. The second number means that there will be three digits following the decimal point. Have a look at help format
if you want to know more about this notation and about other options you have.
The parentheses surrounding r(p)
mean that this expression will be avluated and the result will be written into the file. This is explained in help file
.