[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: qs on generate command
I'm assuming that you presently have a variable named "country", with
records that include "brunei" or "cambodia". For those entries you'd like
the new variable, "region" to read "east asia and pacific". There's a
detail with creating variables containing strings that you need to be aware
of. When you use the -gen- command, the first argument following the command
is set_type, which should be "str" followed by the maximum number of
characters you expect to use in the string. For example, "east asia and
pacific" has 21 characters in it (including space characters), so you need
to use at least "str21", at the expense of a few more bytes you can round
that up to 30 for str30, as follows:
-gen str30 region = "east asia and pacific" if country =="brunei" | country
Stata would then create the region variable, populate the records for brunei
and cambodia with "east asia and pacific", and then tell you it generated a
number of "missing values" for those records whose country is neither
cambodia nor brunei. As you continue to classify countries into regions
(perhaps "south asia and indian" for bangladesh, india, pakistan and ceylon)
you no longer use "generate" since the variable already exists. You would
use -replace-, since you're changing the missing value in the region to
"south asia and indian". Note that since you've already created the string
variable, you don't need to specify the str30 set_type:
-replace region = "south asia and indian" if country == "bangladesh" |
country == "pakistan" | country == "ceylon" | country == "india"-
Hopefully this is what you were looking for.
3380 Central Expressway 609C
Santa Clara, CA 95051
From: email@example.com [mailto:firstname.lastname@example.org]
Sent: Wednesday, March 26, 2003 9:22 AM
Subject: st: qs on generate command
I am trying to classify regions.
generate region = east asia and pacific if country "brunei, cambodia"
Whats the correct way?
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.462 / Virus Database: 261 - Release Date: 3/13/2003
* For searches and help try: