I want to write a TeX file in Stata which contains a p-value rounded to the nearest .001. Since sutex, outtab, etc doesn’t have built-in capabilities for post-estimation results, I’ve tried a bunch of things like
file write myfile %4z "`r(p)'"
or
gen temp = round( `r(p)',.001)
format temp %4.3f
sum temp, f
file write myfile " & `r(mean)'"
Any ideas?
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.
I have specified a
5.3fformat. 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 athelp formatif 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 inhelp file.