Hello!
I am using partyid4.dta from the SPost13 add on with Stata/IC 14.0
I am trying to follow the example in the book by Long & Freese (2014), p.420, Regression models for categorical dependent variables using Stata
The example aims to plot the marginal effects of a multinomial regression. The following code tries to create a local macro and a forvalues loop.
Explanation of the code: Line 1 generates the multinomial regression, line 2 creates and labels the variable that will hold the discrete change for each observation. The command to label the variable incomedc did not work, so i tried another command in line 5.
line 6 and 7 compute the standard deviation and create the local macro sd containing the standard deviation. This is used in the margins command in line 12.
Line 8 creates the macro nobs with the number of observations, which we is used in line 9 to begin a forvalues loop through the 1,382 observations in the estimation sample.
The loop over observations is defined in lines 9 through 17. Line 10 uses quietly to suppress the output from margins. Line 11 uses margins to compute predictions for observation 'i' for the second outcome category where nose suppresses the computation of the standard error.
The first at() statement specifies the observed values of income, with all other variables held at their observed values. The second at() specifies the prediction at one standard deviation more than the observed value.
margins returns the predictions to the matrix r(b), and lines 13 and 14 retrieve the starting and ending probabilities. Line 15 computes the discrete change. Line 16 saves the effect for observation 'i' of variable incomedc.
The last line terminates the quietly command and the forvalues loop. However, Stata gives me an error that the command in line 17 is invalid.
I am using partyid4.dta from the SPost13 add on with Stata/IC 14.0
I am trying to follow the example in the book by Long & Freese (2014), p.420, Regression models for categorical dependent variables using Stata
The example aims to plot the marginal effects of a multinomial regression. The following code tries to create a local macro and a forvalues loop.
Explanation of the code: Line 1 generates the multinomial regression, line 2 creates and labels the variable that will hold the discrete change for each observation. The command to label the variable incomedc did not work, so i tried another command in line 5.
line 6 and 7 compute the standard deviation and create the local macro sd containing the standard deviation. This is used in the margins command in line 12.
Line 8 creates the macro nobs with the number of observations, which we is used in line 9 to begin a forvalues loop through the 1,382 observations in the estimation sample.
The loop over observations is defined in lines 9 through 17. Line 10 uses quietly to suppress the output from margins. Line 11 uses margins to compute predictions for observation 'i' for the second outcome category where nose suppresses the computation of the standard error.
The first at() statement specifies the observed values of income, with all other variables held at their observed values. The second at() specifies the prediction at one standard deviation more than the observed value.
margins returns the predictions to the matrix r(b), and lines 13 and 14 retrieve the starting and ending probabilities. Line 15 computes the discrete change. Line 16 saves the effect for observation 'i' of variable incomedc.
The last line terminates the quietly command and the forvalues loop. However, Stata gives me an error that the command in line 17 is invalid.
:
1] mlogit party age income i.black i.female i.educ, base (5) (output omitted) 2] . gen incomedc = . label var incomedc /// "Effect of a one standard deviation change in income on Pr(Dem)" invalid 'label' r(198); 3] . gen incomedc = . 4] (1,382 missing values generated) 5] . label variable incomedc "Effect of a one standard deviation chang in income on Pr(Dem)" 6] . sum income (output omitted) 7] . local sd = r(sd) 8] . local nobs = _N 9] . forvalues i = 1/'nobs` { 10] 2. quietly { 11] 3. margins in 'i`, nose predict(outcome(2)) 12] 4. Dem at(income=gen(income)) at(income=gen(income+'sd`)) 13] 5. local prstart = el(r(b) ,1,1) 14] 6. local prend = el(r(b) ,1,2) 15] 7. local dc = 'prend` - 'prstart' 16] 8. replace incomedc = 'dc` in 'i` 17] 9. }} invalid syntax r(198); . } } is not a valid command name r(199);