display

Working as a calculator

Stata can be used as a calculator interactively. display followed by an expression will display the results right away.
. display 100^2

10000
. display %6.0fc 100*100
10,000
. display as text "the square root of 10000 is " sqrt(10000)
the square root of 10000 is 100
. display _pi
3.1415927
. display normal(0.5)
0.69146246

Displaying the results while a program runs

It is useful in some cases to display results on the screen while a program runs, which allows us to see where we are and to check if the codes are correct.

Below we included display "`var':" `i' " vs " `i'+1 so that we knew which variable and which pair it was being performed on; we also could spot anything abnormal right away while the program was running.


sysuse auto

local i = 1
while `i' < 3{
	foreach var in price mpg {
		display "`var':" `i' " vs " `i'+1
		estpost ttest `var' if rep78 == `i' | rep78 == `i'+1, by(rep78)
	}
	local i = `i' + 1
}		
		


price:1 vs 2

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
       price | -1403.125         10   2650.997  -.5292821          8   .3054887   .6109774   .6945113          2     4564.5          8   5967.625 
mpg:1 vs 2

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
         mpg |     1.875         10   3.021731   .6205052          8   .7239061   .5521877   .2760939          2         21          8     19.125 
price:2 vs 3

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
       price | -461.6083         38   1406.913     -.3281         36   .3723684   .7447368   .6276316          8   5967.625         30   6429.233 
mpg:2 vs 3

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
         mpg | -.3083333         38    1.61937  -.1904033         36   .4250314   .8500628   .5749686          8     19.125         30   19.43333 

		

The output could have been confusing without any marks.


             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
       price | -1403.125         10   2650.997  -.5292821          8   .3054887   .6109774   .6945113          2     4564.5          8   5967.625 

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
         mpg |     1.875         10   3.021731   .6205052          8   .7239061   .5521877   .2760939          2         21          8     19.125 

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
       price | -461.6083         38   1406.913     -.3281         36   .3723684   .7447368   .6276316          8   5967.625         30   6429.233 

             |      e(b)   e(count)      e(se)       e(t)    e(df_t)     e(p_l)       e(p)     e(p_u)     e(N_1)    e(mu_1)     e(N_2)    e(mu_2) 
-------------+------------------------------------------------------------------------------------------------------------------------------------
         mpg | -.3083333         38    1.61937  -.1904033         36   .4250314   .8500628   .5749686          8     19.125         30   19.43333 
			
		

Author: Yun Dai, 2018