12. Regression analysis in Stata with continuous, numeric and categorical independent variables
Hello guys my name is. Khan and actually in today's video I will show you guys that how you can do basic regression analysis in Stata so for this I will be using auto data and I have created a basic regression. Do for you guys go over so I will open my new file so I'm using Auto data then I am first giving working directory. Path that varies metallized located. Then I'm executing the score control shipped home and then control D to get C. Cute the goal. If you come here you can see that. I have my data uploaded instead up and now I will show that if you want to see that how this price variable get impacted by the MPG which is the mileage that if I want to know that if MPG increased by one unit how it will impact the price so for that kind of thing analysis you will have to do regression analysis so if I say re g RG is for regression and then I will. After regression you have to select the dependent variable which is in this case is price and after dependent variable you have to slide select the independent variable and I will select mpg and now if I enter you can see the stat. I have created a very nice table for regression table for us. And here you can see a very important result. Regression is that if the mpg increased by one unit the prices are going to decrease but 238 units and you can also see that this coefficient is very statistically significant. Another thing important thing. I like to highlight that spot. If you want to show this result to your supervisor or your professor so you can just simply then slap this table and then right-click it and then you can copy it as a picture and if I go to Word document if I paste it here you can see that how easily you have extracted the result from Stata to a Word document then you can share this table with anyone you like. I'm going back to my Stata window and now suppose if you also want to use the any output result into your calculation then if that is also very easy if I say in return list you can see this data is in Stata will give you that hub that butter how many scalars or matrices stat I have created for after this regression come on so and if you want to see that how many so instead I have created one scalar and of one matrix and the matrix contains all the values that you can extract from here so if I save mad list and our matrix there is our table you can see that all the values or matrix are here and all these values are coming from this table the regression table and you can extract any part of that value in suppose if you want to use in your calculation you can assign them to a local because sometimes when you're recording in Stata you may need these coefficients to be used in your calculations so now after that I will show you guys that if you have to do if you have not also want to see that how prices got impacted not only by mpg but also suppose with the length so that is also very easy we will say to rewrite a Midrash and then you will say select the independent variable so independently and after that I will select my two independent variables which is mpg and grade so you can see that now we have I have two independent variables and Stata is showing us about the coefficients but in this regression an important thing to see is that the three variables that I am using price mpg and Wade are all continuous variable so the continuous variables mean that they can take any value so any value from the scale from 0 to 100 but continuous variable also can take any value from negative infinity to positive infinity and now I will show you where this pose if I want to add add an independent variable which is not continuous which is categorical variables so suppose I want to add a variable for n so I will show you guys what is important variable so if I say here so you can see that foreign variable is a categorical variable it's taking only two values actually domestic and foreign are actually just labels so I so in order to show the actual values of foreign I'm saying annual which is four means no label so as you can see foreign variable is 0 1 and suppose now if I want to include foreign as a independent variable in a regression so if I say regress my independent is my dependent variable is price then I'm using mpg and if I select M for n so suppose if I enter this command this data will not give you an error but this Russian will not be right because Stata will consider foreign as a continuous variable and which will impact our reserves reserves will be biased here step but I am repeating here.
This data will not give you an error but the results that you will get in. This table will be biased and will not be considered as right so in order to make the right reserves you have to write down the command this way so he will. I didn't write down price and mpg is the same way but I will before four and I will say I B so I will select I believe that which category of foreign variable will be used at the base category. And suppose for this. I will be using zero as my base category so Mazzio means that zero base category impacts will be included in the constant variable. So if you want to know what does it mean. I think if you are doing regression analysis if you are familiar with the regression you will get my point that what I am trying to say here so now as I enter so I have I think selected but wrong come on and it's try to do it again so I will say I be one sorry I am doing it. I have to select first one. And then don't as you can see that now everything is fine so you have to write down ID and then the door will come after one or zero so you can make it here zero. I will also be able same come on with zero so you can see that not working fine so this is a very basic overview about how you can do regression in Stata but if you want to know more about regression linear regression I will say that you can help a progressed and you can go here. There is a very very detailed overview about how regression command works in.
Stata and what are the things you can do so the Stata have also given some very good examples about how you can do regression. How you can use categorical variable. You can also combine regression with the if command.
This data will not give you an error but the results that you will get in. This table will be biased and will not be considered as right so in order to make the right reserves you have to write down the command this way so he will. I didn't write down price and mpg is the same way but I will before four and I will say I B so I will select I believe that which category of foreign variable will be used at the base category. And suppose for this. I will be using zero as my base category so Mazzio means that zero base category impacts will be included in the constant variable. So if you want to know what does it mean. I think if you are doing regression analysis if you are familiar with the regression you will get my point that what I am trying to say here so now as I enter so I have I think selected but wrong come on and it's try to do it again so I will say I be one sorry I am doing it. I have to select first one. And then don't as you can see that now everything is fine so you have to write down ID and then the door will come after one or zero so you can make it here zero. I will also be able same come on with zero so you can see that not working fine so this is a very basic overview about how you can do regression in Stata but if you want to know more about regression linear regression I will say that you can help a progressed and you can go here. There is a very very detailed overview about how regression command works in.
Stata and what are the things you can do so the Stata have also given some very good examples about how you can do regression. How you can use categorical variable. You can also combine regression with the if command.