command | [action] |
---|---|
5.1. recode var list (rule) | [ changes the values of numeric variables according to the rules specified alters data] |
5.2. rename old varname new varname | [ changes the name of existing variable ] |
5.3. generate newvar = exp | [ creates a new variable. The values of the variable are specified by = exp ] |
5.4. replace varname = exp | [ changes the contents of an existing variable alters data ] |
Now that you know how to load data. We can begin manipulating variables. First, lets load some data. This is data from my survey about immigration attitudes. It includes a Disgust Sensitivity Scale. To load the data from the we, type:
    use
    describe
    generate
gender2 = gender
    recode
gender2 (2=0)
    rename
gender2 male
Next we have 5 questions about support for immigration. We can add these questions together to make an index of immigration attitudes. But we have to be careful. " of the variables (immig_attitude2 and immig_attitude4) code negative attitudes as high scores. The other variables code positive values as high scores. First we need to invert the 2 negative questions.
    sum
immig_*
    replace
immig_attitude2 = immig_attitude2*-1
    sum
immig_attitude2
    replace
immig_attitude2 = immig_attitude2+6
    sum
immig_attitude2
    replace
immig_attitude4 = (immig_attitude4*-1)+6
    sum
immig_*
    generate
support = immig_attitude1 + immig_attitude2 + immig_attitude3 + immig_attitude4 + immig_attitude5
    reg
support male educ age DSS