* Algebra * The GoG graphical algebra is related to the algebra of * model specification. * Wilkinson suggests there are three basic operations in a * graphical algebra: * (1) cross, which he denotes "*" * (2) blend, which he denotes "+" * (3) nest, which he denotes "/" clear all sysuse auto generate maker = substr(make, 1, strpos(make, " ")-1) replace maker = make if strpos(make, " ")==0 ****** * a simple "cross", y*x scatter mpg weight ****** * a simple "blend", z+y, puts two variables on * the same scale * multiple, layered crosses, (z+y)*x, are a cross of a blend scatter disp mpg weight * in our graphical algebra (z+y)*x = z*x+y*x, a blend of two crosses * so it should be no surprise that an equivalent graph is twoway (scatter disp weight) (scatter mpg weight) * likewise in the world of categorical variables, a cross * (weight*rep78) in Wilkinson's notation graph dot weight, over(rep78) * we can blend categorical axes, weight*(rep78+foreign) graph dot weight, over(rep78) over(foreign) * and we can have multiple crosses, (price+weight)*rep78 graph dot price weight, over(rep78) * in Stata we cannot overlay plots that have categorical axes, * that is, we cannot specify (price*rep78)+(weight*rep78) * so there is no alternate specification here ****** * We also have a "nesting" operation. Graphically this gives us * separate panels. (mpg*weight)/foreign scatter mpg weight, by(foreign) graph dot price, over(rep78) by(foreign) * however some statistics with some categorical variables cannot be nested graph hbar (count), over(rep78) graph hbar (count), over(rep78) by(foreign) // obtuse error message * So we resort to extra manipulation to get what we want: preserve contract rep78 foreign graph hbar (asis) _freq, over(rep78) by(foreign) restore * Stata accomodates nesting-within-nesting, so * (mpg*weight)/rep78/foreign, a.k.a. (mpg*weight)/(rep78+foreign) scatter mpg weight, by(rep78 foreign) * but it doesn't really give us nesting within a cross, * if we want (mpg*weight)/(rep78*foreign) we have to do it by "hand" scatter mpg weight, by(rep78 foreign, cols(2) holes(2 4)) graph dot price, over(maker) nofill by(rep78 foreign, cols(2) holes(2 4))