/*** 2SLS with example from Gujarati p685 index of crop production, 1977=100 index of crop prices received by farmers, 1977=100 real per capita personal consumption expenditure use data from http://www.presidency.ucsb.edu/economic_reports/1993.pdf tables B-94, B-96 and B-5 ***/ /* change the directory to point to your file */ proc import datafile="g:\Teaching\ECN410\ECN410.Beamers\Lecture6\2SLS.xlsx" dbms=xlsx out=work.two_stage replace; getnames=yes; run; proc contents data=two_stage; run; /* stage one estimate the price as s function of the exogenous variable */ proc reg data=two_stage; model price_index=cons_expend; output out=two_stage p=price_hat; run; proc reg data=two_stage; model crop_index=cons_expend; run; /* stage 2, use the estimated price in the regression equation */ title '2SLS, see Gujarati (1995 p. 685)'; proc reg data=two_stage; model crop_index = price_hat; run; title ; QUIT; /** END EXAMPLE OF 2SLS **/ /* EXAMPLE CALCULATING ELASTICITY data are for 2014 From http://www.eia.gov/electricity/data.cfm Find "Sales (consumption), revneue, prices & customers" then under "Retail sales of electricity to ultimate customers" go to "Annual" and then "By state and utility" and then choose "Residential sector" which leads to the file immediately below as accessed Oct 3, 2016. http://www.eia.gov/electricity/sales_revenue_price/xls/table6.xls http://www.eia.gov/electricity/data/eia826/ */ /* change the directory to point to your file */ proc import datafile="g:\Teaching\ECN410\ECN410.Beamers\Lecture6\electricity_prices.xlsx" dbms=xlsx out=work.electricity replace; getnames=yes; run; proc contents data=electricity; run; /*note: in this file we have CUSTOMERS: number of customers SALES: number of megawatt hours of electricity REVENUES: revenue from electricity sales measured in $1000 AVERAGE_PRICE: the average price of electricity measured in cents per kilo watt hour */ data electricity; set electricity; where average_price gt 0; LNSALES=log(sales/customers); LNPRICE=log(average_price); average_sales=sales/customers; my_average_price=(revenues*1000*100/(sales*1000)); /*mega watt is 1000 kilowatts and a thousand $ is 100*1000 cents*/ difference=my_average_price-average_price; run; proc means data=electricity; run; proc reg data=electricity; model sales = average_price; run; /* the above looks awful which shouldn't be surprising */ /* estimate the sales on a per customer basis */ proc reg data=electricity; model average_sales = average_price; output out=influential cookd=cd; run; /* try the log-log model */ proc reg data=electricity; model lnsales = lnprice; run; QUIT; /*look at some of the influential observations*/ proc univariate data=influential; var cd average_price; run; proc sort data=influential; by descending cd; run; proc print data=influential (obs=20); run; /* Where is Block Island? */ /* for comparison drop some observations with extreme prices */ data influential2; set influential; where average_price lt 40; proc means data=influential2; proc reg data=influential2; model average_sales = average_price; run; quit;