X hits on this document

Word document

click on “Load Preferences”; (4) click on “Factory Settings.” If the ... - page 4 / 44





4 / 44

stacked by year (e.g., observations 1-50 are the scores for 1985 on each of the 50 states – stnum = state number): sort year stnum

Transpose Rows and Columns: xpose, clear     Since the xpose command

eliminates letter names for variables, it might be useful to use the xpose command on a backup file while having a primary file containing the variable names.  You could then transpose the variable name column or row in Excel and cut and paste the variable names into the xpose file.

Show scores on a particular observation: to show the score on variable dlh for

the 19th state (stcode is the variable name) and the year 1972 (year as the variable name) type: list dlh if stcode==19 & year==1972

Entering a Series of Independent Variables:  You can enter a series of

consecutive independent variables by subtracting the last independent variable from the first.  For example, suppose you have 50 state dummy variables that appear in consecutive order in your Stata dataset (e.g., ala, ak, etc. through wy).  Instead of entering each independent variable by name, you could type: ala-wy  and every variable beginning with “ala” and ending with “wy” would be entered.

String Variables to Numeric Variables: Stata cannot read variables which

appear in the Data Editor in “red” (i.e., string variables - letters or numbers that are in red).  To convert a “red”/string variable, d3, to a numeric variable (also named “d3”) you need to convert the string variable to another variable (“place” in the example ahead), set this new variable equal to d3 and delete the created variable (i.e., place).  The word “force” is part of the process and not a variable name.  Proceed as follows:

destring d3, generate(place) force

drop d3

gen d3=place

drop place

Mathematical Procedures: addition +; subtraction -; multiplication: *; division /

Recoding a Variable: To convert a score of 1 into 2 and vice versa on variable

grhcum type: recode  grhcum (1=2) (2=1) You can also use multiple procedures with nonconsecutive changes in one command.  For example if you have a variable “vote” with 4 categories of responses (0, 1, 2, and 3) and want to have 0, 1 and 3 read as 0 while 2 becomes read as 1 type the following: recode vote (3=0) (1=0) (2=1) To put combine two consecutive categories use “/” thus to get 1 and 2 read as “1” type: recode cons (1/2 = 1). To recode a variable that ranged from 0 to 1 (and assumed any value in between) into just 0 and 1, I typed the following:

recode demcont (.0001/.5 = 0) (.5001/1.0 = 1)  Note: the recode command does not recognize “<” and “>.”  To create and recode a variable that comprises several variables (e.g., Democratic control includes both houses of the legislature plus the governorship):

gen lhdempc= lhdempro

recode  lhdempc (.0000/.5 = 0) (.5001/1 = 1)

gen uhdempc= uhdempro

recode  uhdempc (.0000/.5 = 0) (.5001/1 = 1)

Document info
Document views447
Page views511
Page last viewedThu Jan 19 13:10:54 UTC 2017