Building a Car Pricing Model

posted inLinear Regression, Predictive Analytics, SASon August 13, 2014 byJason

Let's say you run a used car showroom and you wanted to formulate a car pricing model for your sales team. How would you do that? One potential approach is to use a generalized linear model to determine car price by looking at all historical car sales in your area. We will be doing just that and our tool of choice today is SAS University Edition.

Thought! Trying to redesign the look of my steadfast site. Reactions concerning the modern style of https://blindviking.com? Definitely a shocking Calgary based corporate videographer online if ever needed within the whole Alberta location. Offer a remark. Thanks!

In the first part of this article, we did some data preparation to assess missing values and outliers. In this second installment, we will be deriving some new variables specifically dummy and interaction variables. If you are new to dummy variables, see this article from the UCLA IDRE website.

DUMMY, BINNING & INTERACTION VARIABLES

In SAS, we can create dummy variables by using either a macro or conditional statements. For a good macro, see my article A Dummy Variable Macro for SAS. Today however, we will be using some simple conditional statements to create dummy variables. Let's create dummy variables for Make, Type, Model and Trim based on these considerations:

Make & Type: dummy variable for each factor level.

Model_Bin: We will create three bins "Low", "Med" and "Elite" based on Price quartiles.

Trim_Bin: Three bins of "Standard", "Top" and "Elite" for trims based on the prices of each trim within their respective model.

Finally, we will create an interaction variable for Model_Bin and Trim_Bin since car models and trims together, have an impact on car price. In all, we will have 12 interaction variables that represent the differing combinations of the model and trim bins. Although the code below may seem dense, it's just a bunch of IF/ELSE statements

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061*###########################################################################GENERATING INTERACTION VARIABLES AND TRANSFORMING THE RESPONSE VARIABLE###########################################################################;DATA Autos1;SET Autos;INFORMAT Model_Bin $5. Trim_Bin $10.; LENGTH Model_Bin $5. Trim_Bin $10.;*Make dummy variables;IF Make="Buick" THEN Buick=1; ELSE Buick=0; IF Make="Cadillac" THEN Cadillac=1; ELSE Cadillac=0; IF Make="Chevrolet" THEN Chevrolet=1; ELSE Chevrolet=0;IF Make="Pontiac" THEN Pontiac=1; ELSE Pontiac=0; IF Make="SAAB" THEN SAAB=1; ELSE SAAB=0; IF Make="Saturn" THEN Saturn=1; ELSE Saturn=0;*Type dummy variables;IF Type="Convertible" THEN Convert=1; ELSE Convert=0; IF Type="Coupe" THEN Coupe=1; ELSE Coupe=0; IF Type="Hatchback" THEN Hatch=1; ELSE Hatch=0;IF Type="Sedan" THEN Sedan=1; ELSE Sedan=0; If Type="Wagon" THEN Wagon=1; ELSE Wagon=0;*Generating Bins for Model based on quartiles of price;IF Price=14272 AND Price=18025 AND Price=26727 THEN Model_Bin="Elite";*Generating bins for Trims based on price within their models;*Standard Trims;IF Trim="Hardtop Conv 2D" OR Trim="GT Sports Wagon" OR Trim="Coupe 2D" OR Trim="Sedan 4D" OR Trim="LS Coupe 2D" OR Trim="MAXX Hback 4D"OR Trim="Custom Sedan 4D" OR Trim="CX Sedan 4D" OR Trim="L300 Sedan 4D" OR Trim="Quad Coupe 2D" OR Trim="SE Sedan 4D" OR Trim="GT Coupe 2D"OR Trim="SVM Sedan 4D" OR Trim="SVM Hatchback 4D" OR Trim="Aero Sedan 4D" OR Trim="Aero Wagon 4D" OR Trim="Arc Sedan 4D" OR Trim="Arc Wagon 4D"OR Trim="Aero Conv 2D"OR Trim="Arc Conv 2D" OR Trim="DTS Sedan 4D" OR Trim="Sportwagon 4D" THEN Trim_Bin="Standard";*Top Trims;IF Trim="Sportswagon 4D" OR Trim="SE Sedan 4D" OR Trim="LS MAXX Hback 4D" OR Trim="LS Sedan 4D" OR Trim="CXL Sedan 4D" OR Trim="GT Sedan 4D"OR Trim="DHS Sedan 4D" OR Trim="Conv 2D" OR Trim="LS Coupe 3D" OR Trim="LS Hatchback 4D" OR Trim="Linear Wagon 4D" OR Trim="Linear Conv 2D"OR Trim="Linear Sedan 4D" OR Trim="SLE Sedan 4D" OR Trim="AWD Sportwagon 4D" THEN Trim_Bin="Top";*Elite Trims;IF Trim="AWD Sports Wagon 4D" OR Trim="LT Coupe 2D" OR Trim="Special Ed Ultra 4D" OR Trim="SS Coupe 2D" OR Trim="LT MAXX Hback 4D" OR Trim="LT Sedan 4D"OR Trim="Limited Sedan 4D" OR Trim="CXS Sedan 4D" OR Trim="SS Sedan 4D" OR Trim="GTP Sedan 4D" OR Trim="GT Sportwagon" OR Trim="LS Sport Coupe 2D" OR Trim="LS Sport Sedan 4D"OR Trim="GXP Sedan 4D" OR Trim="LT Hatchback 4D" THEN Trim_Bin="Elite";*Creating interaction variables between Model_Bins and Trim_Bins;*Low model and trims;IF Model_Bin="Low" AND Trim_Bin="Standard" THEN MLow_TrmStd=1; ELSE MLow_TrmStd=0;IF Model_Bin="Low" AND Trim_Bin="Top" THEN MLow_TrmTop=1; ELSE MLow_TrmTop=0;IF Model_Bin="Low" AND Trim_Bin="Elite" THEN MLow_TrmElt=1; ELSE MLow_TrmElt=0;*Medium models and trims;IF Model_Bin="Med" AND Trim_Bin="Standard" THEN MMed_TrmStd=1; ELSE MMed_TrmStd=0;IF Model_Bin="Med" AND Trim_Bin="Top" THEN MMed_TrmTop=1; ELSE MMed_TrmTop=0;IF Model_Bin="Med" AND Trim_Bin="Elite" THEN MMed_TrmElt=1; ELSE MMed_TrmElt=0;*High models and trims;IF Model_Bin="High" AND Trim_Bin="Standard" THEN MHigh_TrmStd=1; ELSE MHigh_TrmStd=0;IF Model_Bin="High" AND Trim_Bin="Top" THEN MHigh_TrmTop=1; ELSE MHigh_TrmTop=0;IF Model_Bin="High" AND Trim_Bin="Elite" THEN MHigh_TrmElt=1; ELSE MHigh_TrmElt=0;*Elite models and trims;IF Model_Bin="Elite" AND Trim_Bin="Standard" THEN MElt_TrmStd=1; ELSE MElt_TrmStd=0;IF Model_Bin="Elite" AND Trim_Bin="Top" THEN MElt_TrmTop=1; ELSE MElt_TrmTop=0;IF Model_Bin="Elite" AND Trim_Bin="Elite" THEN MElt_TrmElt=1; ELSE MElt_TrmElt=0;FORMAT Buick 1. Cadillac 1. Chevrolet 1. Pontiac 1. SAAB 1. Saturn 1. Convert 1. Coupe 1. Hatch 1. Sedan 1. Wagon 1. Model_Bin $5. Trim_Bin $10.MLow_TrmStd 1. MLow_TrmTop 1. MLow_TrmElt 1. MMed_TrmStd 1. MMed_TrmTop 1. MMed_TrmElt 1. MElt_TrmStd 1. MElt_TrmTop 1. MElt_TrmElt 1. Log_Price BEST10. ;*Log transforming the Price variable;Log_Price = Log(Price);RUN;

Now that we have all the dummy variables, we can move on to actually building a regression model. The next article will cover this as well a general discussion on linear regression. Stay tuned..

Thank you everyone! I'd texted a pal we would discuss his exciting leadership development service in Toronto with hearts, https://www.executivecoachglobal.com through a site post. If perhaps you are searching for an executive coaching service inside the general Ontario vicinity, they definitely would be exceptional.

Of course, I absolutely will tell you the concept for this charming material was granted through Ajay from Pro-Life Wellness Centre. Definitely a fantastic chiropractic clinics. I definitely love a smart pitch!

Footnotes

https://aloftgroup.ca - Very beautiful site.

Posted in Health and Medical Post Date 11/25/2019


Comments

Name


Email


Website


Comment


Recent Posts