júní 20, 2011

Using by/if/in

Now we have used the previous commands on the data set without specific or orderly sequence.

Suppose you want to describe, browse, or even summarize a group of variables in the data set? Did I really intend to ask you this or should I be answering this?

Its possible to analyze just a sample or portion of data set by use of the following conditional options

  • IF
  • IN
  • BY

IF

Executes a command when the set condition is met

Syntax: command  [variable(s)] if (condition)

example: 1) summarize age if (age>10)

  2)list make price if foreign==1

  3)list make price if price > 10000 & price <.

Explanation: 1) will only execute the command summarize on variable age on only the occurrences where age is greater than ten.

              2) Will list prices of only foreign cars .(to load this data, enter sysuse auto in the command window)

             3) Will list only prices greater than 10000 and value is not missing

Other possible operators include less than(<), less than or equal to(<=), greater than or equal(>=), not equal to(!=), if missing

Now that I have mentioned “missing”, let me tell you something about “missing”. If a variable of type numeric has no value, Stata uses dot(.) to show this. If the variable was of type string, it is shown by a blank(“ “).

IN

Used to specify  a range

Syntax: command summarize [variable] in 1/20

This will display a summary of variable 1 through to 20

BY

Primarily used to sort data

As a prefix:

When a command is prefixed with a bylist, it is performed repeatedly for each element of the variable or variables in that list, each of which must be categorical. For instance,
by foreign: summ price
will provide descr iptive statistics for both foreign and domestic cars. If the data are not already sorted by the bylist variables, the prefix bysort should be used. The option ,total will add the overall summar y.

Examples:

bysort rep78: summ price
bysort rep78 foreign: summ price

As a suffix:

summarize price, by(foreign)

Engin ummæli:

Skrifa ummæli