gen demcont = lhdempc + uhdempc + demgov

recode demcont (.0001/2.999 = 0) (3 = 1)

To recode nonconsecutive numbers use multiple commands. In creating state dummy variables from a state number variable (“stnum” coded 1 through 50) I did the following: gen al=stnum then with a second command: recode al (1=1) (else=0) To recode a percentage variable, “cons,” into three categories (e.g., 0-33=1, etc.) type: recode cons (0/33=1) (34/66=2) (67/100=3) or you can accomplish the same operation as follows: gen cons1 = 1 if cons < 34 (press “enter”)

replace cons1 = 2 if cons >= 34 (press “enter”)

replace cons1 = 3 if cons >= 67 (press “enter”) (double check which way the arrows point – think through if it should be “<” or “>”)

Note: if you are using the above commands for one value you need two

consecutive equal signs. Thus, gen cons1=1 if cons ==34 (would be if you wanted a score of “1” on cons1 to equal a score of 34 on cons).

Recoding to Percentiles: There is a command called the "xtile" command that will recode the observations based on which percentile (ranges) of a distribution the data are in. xtile lownetinc5 = networthlow_06, nq(5) Where the new variable would be "lownetinc5" , the old variable would be "networthlow_06" and the number of categories for the new variable would be indicated by the nq (5) if you wanted 5 categories.

Absolute Values: to recode a variable with positive and negative values

to all positive values type: gen margin= abs(diff) This converted

negative values on “diff” to all positive for new variable “margin.”

Converting electoral “margin” into two categories (less than 3% = 1 and greater than 3% = 0), I did the following: (1) gen margin3less=.

(2) replace margin3less=1 if margin<.03001

(3) replace margin3less=0 if margin>.03

Percentage Change Variable:

tsset stnum year, yearly (means time series)

gen income = (pcdinc-pcdinc[_n-1])/pcdinc[_n-1]

gen pcdincpch=income*100

Percentage Change Over Time:

For a dataset stacked by state and year (obs. 1-24 were for state #1, with

obs. 25 being the first year for state #2) to get the percentage change in population (popi) over presidential administrations beginning in 1981 and ending with 2004 (i.e., change over 2001-2004) I did the following (after the data were “tsset”):

gen pchange = (f3.popi-popi)/popi

list pchange if year == 1981 & 1985 & 1989 & 1993 & 1997 & 2001

Converting Monthly Data to Annual Data: for a dataset with the following

variables: year, month (numbered 1 through 12 – i.e., 12 entries for each year) and minwage (the state’s minimum wage in that particular month of