Translation of examples in Stata tip 106: With or without reference to Stata version 10 or less

Maarten L. Buis

Abstract

The examples in the article Stata tip 106: With or without reference uses factor variables, which are new in Stata 11 . However the logic of the argument in this article also applies to earlier versions of Stata (and other statistical packages). Below is Stata code for the same examples that can be run in earlier versions of Stata.

. sysuse auto, clear (1978 Automobile Data)

. . //================================================= example 1 . sum weight if foreign == 0, meanonly

. gen c_weight = (weight - r(min))/2000

. label var c_weight /// > "weight centered at lightest domestic car (short tons)"

. . // manually create an additional indicator variable . gen byte domestic = !foreign if foreign < .

. . qui reg price foreign c_weight

. est store a1

. qui reg price foreign domestic c_weight, nocons

. est store b1

. . // the keep() option is used to make sure that the order . // in which the variables appear corresponds with the . // order in the original article . est tab a1 b1, b(%9.3g) /// > keep(domestic foreign c_weight _cons)

-------------------------------------- Variable | a1 b1 -------------+------------------------ domestic | 1034 foreign | 3637 4671 c_weight | 6641 6641 _cons | 1034 --------------------------------------

. . //================================================= example 2 . gen byte good = rep78 >3 if rep78 < . (5 missing values generated)

. . // manually create an additional indicator variable and . // the interaction terms . gen byte bad = !good if good < . (5 missing values generated)

. gen byte goodXforeign = good*foreign (5 missing values generated)

. gen byte badXforeign = bad *foreign (5 missing values generated)

. gen byte goodXdomestic = good*domestic (5 missing values generated)

. gen byte badXdomestic = bad *domestic (5 missing values generated)

. . qui reg price foreign good goodXforeign c_weight

. est store a2

. qui reg price foreign domestic /// > goodXforeign goodXdomestic c_weight, nocons

. est store b2

. qui reg price goodXforeign badXforeign /// > goodXdomestic badXdomestic c_weight, nocons

. est store c2

. . est tab a2 b2 c2, b(%9.3g) /// > keep(domestic foreign good /// > badXdomestic goodXdomestic /// > badXforeign goodXforeign /// > c_weight _cons)

-------------------------------------------------- Variable | a2 b2 c2 -------------+------------------------------------ domestic | 974 foreign | 3150 4124 good | -251 badXdomestic | 974 goodXdomes~c | -251 723 badXforeign | 4124 goodXforeign | 708 457 4581 c_weight | 6711 6711 6711 _cons | 974 --------------------------------------------------

. . //================================================= example 3 . qui glm price foreign c_weight, link(log) eform

. est store a3

. qui glm price foreign domestic c_weight, /// > nocons link(log) eform

. est store b3

. . est tab a3 b3, b(%9.4g) eform /// > keep(domestic foreign c_weight _cons)

-------------------------------------- Variable | a3 b3 -------------+------------------------ domestic | 2102 foreign | 2.145 4509 c_weight | 3.516 3.516 _cons | 2102 --------------------------------------

[do-file]