How to Create a Continuous Variable in Stata for Euros to Dollars

i. and c. prefixes and ##

A handy way to include dummy variables and interaction variables in regression models is to include them as factor variables. The prefixes 'i.' (i for indicator) and 'c.' (c for continuous) are used for this purpose. Furthermore, double hashtags (##) between two or more variables indicate an interaction variable.

If you wish to include a categorical variable into a regression model, it must be included as a series of dummy variables. Otherwise, interpreting the results will be difficult or even impossible. For some reason, Stata does not allow for using string variables as factor variables. Thus, you must first encode the categorical variable as a numeric variable. After encoding the variable, use the 'i.' prefix to include the categorical variable in the regression model.

                sysuse citytemp, clear reg tempjan i.region              
Fig. 1. Including a categorical variable as a factor variable in a regression.

The above figure shows the outcome. Stata automatically includes the categorical variable in the regression model as a series of dummy variables. The first category is left as the comparison group. Here, the comparison group is the Northeastern USA. Hence, the coefficients suggest that the mean temperature in January is lower in the North Central region and higher in the South and West than in the Northeastern USA. The differences are statistically significant as indicated by the low p-values in the rightmost column.

The prefix 'c.' is needed only in interactions. To create an interaction, the variables must be preceded by correct prefixes. If the variable is a dummy variable, the prefix is 'i.'. If the variable is a continuous variable, the prefix is 'c.'. In the below example, an interaction between a car's weight and the dummy indicating country of origin is included in a regression explaining fuel consumption. Note that you need to use double hashtags (##) to create interactions.

                sysuse auto, clear reg mpg i.foreign##c.weight              

This is a very basic textbook example. Running separate regressions for foreign and American cars would give the same results. Since the regression model includes the dummy variable and its interaction with the weight variable, all the differences between the groups are controlled. Thus, the coefficients are exactly the same coefficients that one would get in separate regressions.

Fig. 2. Including an interaction as factor variables.

The above figure illustrates the result. When using double hashtags, Stata includes both the variables separately and the interaction variable between the variables in the regression model. This is as it should be. Never use an interaction without the variables that you use in the interaction variable.

Stata prints the results for the variables foreign and weight on the first two rows of the result window. The next variable is the interaction variable that can be recognized from the hashtag. All the coefficients are statistically significant on the 5% level of confidence because the p-values are all lower than 0.05. Thus, the interpretation is the following: foreign cars have, on average, better mileage than US cars. Weight decreases mileage for both foreign cars and American cars. However, since the interaction variable between the dummy foreign and the weight variable is significant, the marginal effect is different for foreign cars. Moreover, the coefficient for the interaction variable is negative. Thus, an extra pound of weight decreases mileage more for foreign cars than US cars. This is because the coefficients for weight and the interaction variable are added together to get the result for foreign cars. Thus, the negative relation between mileage and weight is steeper for foreign cars.

Note that the weight is measured in pounds, i.e., it is an absolute measure. This is likely the reason for the result that does not make much sense. Foreign cars are much smaller than American cars. Therefore, the relative increase in weight is higher in foreign cars.

Similar to an interaction between a dummy and continuous variable, factor variables can be used for creating interactions between two dummy variables, two continuous variables or any number of variables. A dummy variable must always be preceded by the prefix 'i.', and a continuous variable by the prefix 'c.'. The interacted variables always have double hashtags between them.

                i.dummy1##i.dummy2##i.dummy3 c.continuous1##c.continuous2              

pettyquirded65.blogspot.com

Source: https://thesis-o-matic.com/factor-variables/

0 Response to "How to Create a Continuous Variable in Stata for Euros to Dollars"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel