cd "C:\Users\Aki\Documents\stata" log using feb28.log, replace *******FEB 28. GRAPHING IN STATA. PART 2****** sysuse auto, clear ***dot chart graph dot (mean) price, over(rep78) //OR: go to Graphics menu - Dot chart - select the statistics to show and the categories //similar to bar chart ****DISTRIBUTIONAL PLOTS***** **it is useful to explore the distribution of key variables before running linear regressions and doing statistical tests **histogram, quantile density plot, kernel density plot histogram price //the variable price is not normally distributed histogram price, bin(20) histogram price, frequency **k-density (kernel density) is a line-based representation of distribution kdensity price //the variable is not normally distributed kdensity price if foreign==0 kdensity price if foreign ==1 graph twoway (kdensity price if foreign==0) (kdensity price if foreign==1) quantile price //useful to test for uniformal distribution. If a variable is distributed uniformally, the dots (observations) would be on the 45 degree line ***BOX PLOT**** graph box price, over(foreign) graph box price weight, over(foreign) //useful to compare the distribution of a variable over different groups ***PIE CHART*** graph pie, over(rep78) ***SCATTERPLOTS WITH FITTED LINES**** scatter price mpg twoway (scatter price mpg) (lfit price mpg) //lfit is for linear fit twoway (scatter price mpg) (qfit price mpg) //qfit is for quadratic fit **to let Stata decide on its own twoway (scatter price mpg) (lpoly price mpg) //looks more like a quasi-linear relationship **CONTOUR PLOT**** ***relationship between three continous variables. Used for mapping usually sysuse sandstone, clear twoway contour depth northing easting **COMBINING GRAPHS*** // twoway () () is to combine graphs with common axis sysuse auto, clear twoway (scatter price mpg if foreign==1, title(Foreign)) (lfit price mpg if foreign==1, name(graph1)) twoway (scatter price mpg if foreign==0, title(Domestic)) (lfit price mpg if foreign==0, name(graph2)) graph combine graph1 graph2 ****LOCAL AND GLOBAL MACROS AND LOOPING*** **local macros is some rule that you write yourself and which is valid only in one do-file and for a single execution of commands *global macros work across all do-files and work until you close your Stata session (be careful with global macros) local varlist "price mpg rep78" sum `varlist' tab rep78 sum `varlist' global varlist "price mpg rep78" sum $varlist tab rep78 sum $varlist reg trunk $varlist //until you close your Stata session, this rule will apply **looping **want to generate a log for each var in the dataset //can do it manually, using gen command //gen logprice = log(price) //gen logmpg = log(mpg) foreach i in price mpg length { gen log`i' = log(`i') su log`i' } foreach var of varlist price - trunk { gen `var'10 = `var'*10 } foreach var of varlist * { gen `var'100 = `var'*100 } log close