Hi,
It happened to me before but I couldn't find a solution. I have a big do file consisting of 10 thousand lines of code. But when I want to execute this code, nothing happens and I get an error. All the file saves, new data generates etc in the code are not happening. I am stuck in resolving the error. If anyone has any help or suggestions I would appreciate it.
And I received this error.
It happened to me before but I couldn't find a solution. I have a big do file consisting of 10 thousand lines of code. But when I want to execute this code, nothing happens and I get an error. All the file saves, new data generates etc in the code are not happening. I am stuck in resolving the error. If anyone has any help or suggestions I would appreciate it.
Code:
***************************************************** ***************************************************** set varabbrev off , permanently set linesize 200 *Initialise version 9.0 clear set mem 730m set more off *set matsize 4000 *set maxvar 32767 local year = 2020 * Policy Years * Original *local policyyear = 2020 *Original Department of Ag "New Afforestation Rates for FP23-27 *local policyyear = 2021 *New Department of Ag "New Afforestation Rates for FP23-27 *local policyyear = 2023 local policyyear = 2023 scalar sc_year = `year' cd c:\ ****************************************************** * Run Parameters - switches to run parts of code ****************************************************** *Which file to import * 0 - BL; 1- SS; 2 - NS; 3 LPN; 4 - JL; 5- Oak *scalar sc_species = 1 * Add Years beyond 60 scalar sc_age60p = 1 * Prepare Data for Carbon Analysis scalar sc_data_prep = 1 * Run Analysis for All Species scalar sc_runallspecies_analysis = 1 * Ash Reconstitution Analysis scalar sc_ashreconstitution = 0 * Carbon Sequestration Policy scalar sc_carbseq_policy = 1 ** Number of Rotations to Simulate scalar sc_rotation_num = 6 * Take extra fuel thinnings from clearfell in CarbonCalc scalar sc_fuel_thinnings = 0 * Carbon Values local co2val_vlist = "1 2 3 4" * Planting Year - required for carbon price scalar sc_plant_year = 2020 * Shadow Price 2015 scalar sc_cv_1 = 20 * Shadow Price 2020 scalar sc_cv_2 = 32 * Shadow Price 2030 scalar sc_cv_3 = 100 * Shadow Price 2040 scalar sc_cv_4 = 163 * Shadow Price 2050 scalar sc_cv_5 = 265 * Carbon Price List local co2price_list = "20 32 100 163" global co2price_list1 = "`co2price_list'" * Discount Rates to be considered local discountrate_vlist = "0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" foreach r in `discountrate_vlist' { * Discount rate sum - 110 years scalar sc_disc`r' = 0 * Discount rate sum - 110 years local l = 30 while `l' <= 500 { scalar sc_disc`l'_`r' = 0 local l = `l' + 1 } * 110 years local y = 0 while `y' <= 110 { scalar sc_disc`r' = sc_disc`r' + 1/((1 + `r'/100)^`y') local y = `y' + 1 } } local co2_analysis_vlist = "tv procval prodval co2val_ha co2val_ha_a producerrevenue timbervolume totpotrevenue pco2val_ha_20 pco2val_ha_32 pco2val_ha_100 pco2val_ha_163 co2val_ha_coal co2val_ha_wood co2val_ha_peatb co2val_ha_kerosene co2val_ha_naturalgas co2val_ha_s_coal co2val_ha_s_peatb co2val_ha_s_kerosene co2val_ha_cement cement_priv fordirpay" local co2_fuel_analysis_vlist = "pco2val_wood_20 pco2val_wood_32 pco2val_wood_100 pco2val_wood_163 pco2val_coal_20 pco2val_coal_32 pco2val_coal_100 pco2val_coal_163 pco2val_peat_20 pco2val_peat_32 pco2val_peat_100 pco2val_peat_163 pco2val_kero_20 pco2val_kero_32 pco2val_kero_100 pco2val_kero_163 pco2val_ng_20 pco2val_ng_32 pco2val_ng_100 pco2val_ng_163 pco2val_cement_20 pco2val_cement_32 pco2val_cement_100 pco2val_cement_163 pco2val_cement_p_20 pco2val_cement_p_32 pco2val_cement_p_100 pco2val_cement_p_163" local co2_fuel_s_analysis_vlist = "pco2val_s_wood_20 pco2val_s_coal_20 pco2val_s_peat_20 pco2val_s_kero_20 pco2val_s_ng_20 pco2val_s_wood_32 pco2val_s_coal_32 pco2val_s_peat_32 pco2val_s_kero_32 pco2val_s_ng_32 pco2val_s_wood_100 pco2val_s_coal_100 pco2val_s_peat_100 pco2val_s_kero_100 pco2val_s_ng_100 pco2val_s_wood_163 pco2val_s_coal_163 pco2val_s_peat_163 pco2val_s_kero_163 pco2val_s_ng_163 cons_fuel_soc_wood_32 cons_fuel_soc_coal_32 cons_fuel_soc_peat_32 cons_fuel_soc_kero_32 cons_fuel_soc_ng_32 cons_fuel_priv_wood cons_fuel_priv_coal cons_fuel_priv_peat cons_fuel_priv_kero cons_fuel_priv_ng" local co2_cons_fuel_analysis_vlist = "cons_fuel_soc_wood_32 cons_fuel_soc_coal_32 cons_fuel_soc_peat_32 cons_fuel_soc_kero_32 cons_fuel_soc_ng_32 cons_fuel_priv_wood cons_fuel_priv_coal cons_fuel_priv_peat cons_fuel_priv_kero cons_fuel_priv_ng" local cvlist = "producerrevenue timbervolume totpotrevenue" ** Alternative Fuel List Options local fuel_vlist = "wood coal peatb kerosene naturalgas" ***************************************************** ***************************************************** * Directories ***************************************************** ***************************************************** ****************************************** * Do-file directories ****************************************** * subst x: "C:\Users\0100680s\OneDrive - National University of Ireland, Galway" local dodir "C:\Users\MrvKr\OneDrive\Desktop\AFFOR\Model\Data_ForestryModel" local dodir "C:\Users\MrvKr\OneDrive\Desktop\AFFOR\Model\Data_ForestryModel" global dodir1 = "`dodir'" ****************************************** * Output Data ****************************************** local outdatadir c:\Users\MrvKr\OneDrive\Desktop\AFFOR\Model\Data_ForestryModel global outdatadir1 = "`outdatadir'" ****************************************** * Original Data ****************************************** local origdatadir "C:\Users\MrvKr\OneDrive\Desktop\AFFOR\Model\FIVEE" global origdatadir1 = "`origdatadir'" local nfsorigdatadir "C:\Users\MrvKr\OneDrive\Desktop\AFFOR\Model\FIVEE" capture log close cd "`origdatadir'\" ****************************************** * Lists of Modelling Options ****************************************** * Scenarios * 1 - Status Quo - 34% Energy Usage * 2 - 34% Energy Usage less 10% - Marginal Impact of Differential Energy Use * 3 - Use thinnings for energy - All thinnings are burnt for energy * 4 - Improve energy use from waste products - Use 10% of residual biomass (The .64) for energy local scenario_vlist = "1" * Species Simulated: 0 Ash/Sycamore, 1 Sitka, 2 Norway Spruce; 3 Lodgepole Pine; 4 Japanese Larch; 5 Oak local species_vlist = "0 1 2 3 4 5" *local species_vlist = "5" * Management Decisions - Thin versus No Thin local thin_vlist = "1 0" * Yield Classes for Ash/Sycamore local bltype_vlist = "4 6 8 10" * Yield Classes for Sitka Spruce local sstype_vlist = "10 12 14 16 18 20 22 24" * Yield Classes for Norway Spruce local nstype_vlist = "12 14 16 18 20 22" * Yield Classes for Japanese Larch local jltype_vlist = "6 8 10 12 14" * Yield Classes for Lodge Pole Pine local lpntype_vlist = "8 10 12 14" * Yield Classes for Oak local oaktype_vlist = "4 6 8" * DPER Assumption scalar sc_r = 4 ****************************************** * Prepare Data ****************************************** if sc_data_prep == 1 { capture log close log using `outdatadir'\Bioeconomic.log, replace foreach species in `species_vlist' { * Open Data File scalar sc_speciesnum = `species' * SS if `species' == 1 { use "$origdatadir1\FIVEEconInputSSPanel.dta", clear global type_vlist = "`sstype_vlist'" } * NS if `species' == 2 { use "$origdatadir1\FIVEEconInputNSPanel.dta", clear global type_vlist = "`nstype_vlist'" } * JL if `species' == 4 { use "$origdatadir1\FIVEEconInputJLPanel.dta", clear global type_vlist = "`jltype_vlist'" } * LPN if `species' == 3 { use "$origdatadir1\FIVEEconInputLPNPanel.dta", clear global type_vlist = "`lpntype_vlist'" } * Oak if `species' == 5 { use "$origdatadir1\FIVEEconInputOakPanel.dta", clear global type_vlist = "`oaktype_vlist'" } cap gen species = `species' cap gen mcsph = 0 cap gen thinsph = 0 *************************************** * Create Early life-cycle *************************************** if `species' != 5 { sort yc thin age * First year with timber volumne cap drop tmin_timbervolumeadj by yc thin: egen tmin_timbervolumeadj = min(timbervolumeadj) if timbervolumeadj > 0 replace tmin_timbervolumeadj = 0 if tmin_timbervolumeadj == . cap drop min_timbervolumeadj by yc thin: egen min_timbervolumeadj = max(tmin_timbervolumeadj) cap drop tage_min_timbervolumeadj gen tage_min_timbervolumeadj = age*(min_timbervolumeadj == timbervolumeadj) cap drop age_min_timbervolumeadj by yc thin: egen age_min_timbervolumeadj = max(tage_min_timbervolumeadj) cap drop atv by yc thin: gen atv = 1/(age_min_timbervolumeadj + 1) cap drop btv by yc thin: gen btv = sum(atv) cap gen mctimbervolume = timbervolumeadj qui replace mctimbervolume = min_timbervolumeadj*btv if timbervolumeadj == 0 drop tmin_timbervolumeadj-btv } cap drop speciesnum gen speciesnum = `species' *************************************** * Add an age 0 for establishment year *************************************** qui save "`outdatadir'\tmp.dta", replace qui keep if age == 1 qui replace age = 0 qui replace mctimbervolume = 0 qui save "`outdatadir'\tmp0.dta", replace qui append using "`outdatadir'\tmp.dta" *Oak already has age 0 if `species' == 5 { use "`outdatadir'\tmp.dta", clear } qui replace speciesnum = `species' qui drop if yc == 0 qui drop if yc == . gen year = `year' + age sort year saveold "`outdatadir'\FIVEEconInputNTHP.dta", replace scalar sc_group = 0 * List of outputs from FORBES Bio-Economics Model local vlist1 = "establishrefor maint insurance fertilizerinspection roadsrepairs inventory spare premiumfarmer premiumnonfarmer thinvolume thinrevenue thinpotrevenue cfelvolume cfelrevenue onceoffrevenue annualrevenues land grant sspercent clearfellhl costsalescfel clearfellprice costofsalesthin thinprice firstthin secondthin subsequentthin financialrotation rotation07 bv thin_vol co2val_ha co2val_ha_peatb co2val_ha_a dtCO2_ag_mc dtCO2_bg_mc dsoil_co2 dhwp_co2 dtCO2_bg_ph dtCO2_tm_mc dtCO2_lf_mc dtCO2_hwp_nir dtCO2_bg_ph dtCO2_tm_mc dtCO2_lf_mc co2val_ha_biocircle co2val_ha_biocircle_thin dtCO2_hwp_nir_thin dtCO2_hwp_nir_biocricle* dtCO2_hwp_nir_biocircle_thin cproducerrevenue ctimbervolume ctotpotrevenue cfelpotrevenue" use "`outdatadir'\FIVEEconInputNTHP.dta", clear * Add Additional Years needed for longer loops longer than the rotation lengths in FIVE qui do "`dodir'\AddAdditionalYears.do" gen type = speciesnum gen rotationperiod = 1 cap drop timbervolume * Assign the Rotation Length, based upon yc, species and thin management qui do "`dodir'\CalcRotationLength2.do" tab speciesnum tab yc thin tab yc thin,sum(rotationlt1) nost nofreq * Calculate potetential clearfell volume and value qui do "`dodir'\CalcClearfellVol.do" save "`outdatadir'\ForestGrowthPanelv9.dta", replace if `species' == 0 { save "`outdatadir'\ForestGrowthPanelv9_BL.dta", replace } ************************************************************** * Create Multiple lifecycles ************************************************************** use "`outdatadir'\ForestGrowthPanelv9.dta", clear * Keep 1 rotation gen rotationnum = 1 qui keep if age <= rotationlt1 save "`outdatadir'\ForestPanelRot1.dta", replace * Create multiple life-cycles local i = 2 while `i' <= sc_rotation_num { use "`outdatadir'\ForestPanelRot1.dta", clear qui replace rotationnum = `i' capture drop minyear sort species yc thin year by species yc thin: egen minyear = min(year) qui replace year = minyear + (`i' - 1)*rotationlt1 + age + (`i' - 1) save "`outdatadir'\ForestPanelRot`i'.dta", replace local i = `i' + 1 } * Append rotations into one panel use "`outdatadir'\ForestPanelRot1.dta", clear local i = 2 while `i' <= sc_rotation_num { qui append using "`outdatadir'\ForestPanelRot`i'.dta" local i = `i' + 1 } save "`outdatadir'\ForestPanel.dta", replace ************************************************************** *Impute Financial Data ************************************************************** * FIVE based financial parameters qui do "`dodir'\FIVEParameters`policyyear'.do" use "`outdatadir'\ForestPanel.dta", clear qui do "`dodir'\ImputeFinancialData.do" if `species' == 1 { } save "`outdatadir'\ForestIncomePanel`policyyear'.dta", replace use "`outdatadir'\ForestIncomePanel`policyyear'.dta", clear ************************************************ * Simulate Carbon Calculation ************************************************ qui do "`dodir'\CarbonPriceParams.do" use "`outdatadir'\ForestIncomePanel`policyyear'.dta", clear * No Energy Scenario for now scalar sc_scenario_energy_scenario = 0 qui do "`dodir'\Carboncalc1.do" save "`outdatadir'\ForestCarbonPanel`policyyear'.dta", replace use "`outdatadir'\ForestCarbonPanel`policyyear'.dta", clear cap gen co2val_ha_peatb = co2val_ha_peatbriquettes cap gen co2val_ha_s_peatb = co2val_ha_s_peatbriquettes cap gen co2val_ha_euro_peat = co2val_ha_euro_peatbriquettes cap gen co2val_ha_peat = co2val_ha_peatb qui keep yc speciesnum mcsph thin rotationperiod rotationlt1 rotationnum year age type `vlist' dhwp_fw* co2val_ha_a co2val_ha_coal co2val_ha_peatb co2val_ha_kerosene co2val_ha_wood co2val_ha_s_wood co2val_ha_naturalgas co2val_ha_s_coal co2val_ha_s_peatb co2val_ha_s_kerosene co2val_ha_s_naturalgas hwp_fw_inflow co2val_ha_cement cement_priv co2val_ha_euro_wood co2val_ha_euro_coal co2val_ha_euro_peat co2val_ha_euro_kerosene co2val_ha_euro_naturalgas dtCO2_ag_mc dtCO2_bg_mc dtCO2_hwp_nir dtCO2_bg_ph dtCO2_tm_mc dtCO2_hl_mc dtCO2_lf_mc hwp_fw_co2_wood hwp_fw_co2_coal hwp_fw_co2_peatbriquettes hwp_fw_co2_kerosene hwp_fw_co2_naturalgas cfelrevenue bv thinvolume timbervolume cfelpotvolume thinvolumeadj cfelvolumeadj cfelpotpsc thinpsc thinrevenue cfelrevenue establishrefor cleaning maint insurance fertilizer inventory inspection roadsrepairs premiumfarmer grant cfelpotpsc thinpsc cfelpotmean* thinmean* co2val_ha co2val_ha_a_actcp save "`outdatadir'\ForestCarbonPanel1_`policyyear'.dta", replace *********************************************************************** * Calculate Income Concepts *********************************************************************** use "`outdatadir'\ForestCarbonPanel1_`policyyear'.dta", clear qui do "`dodir'\CalcIncomeConcepts.do" save "`outdatadir'\ForestCarbonPanel2_`policyyear'.dta", replace * Validation *Create YCEquiv (equivalent to SS) *This is necessary to link to farms, where soil and associated yield class relate to sitka qui do "`dodir'\DoYCEquiv.do" local speciesnum = speciesnum[1] if sc_speciesnum == 0 { scalar sc_eqyc = 8 } if sc_speciesnum == 1 { scalar sc_eqyc = 20 } if sc_speciesnum == 2 { scalar sc_eqyc = 18 } if sc_speciesnum == 3 { scalar sc_eqyc = 10 } if sc_speciesnum == 4 { scalar sc_eqyc = 10 } if sc_speciesnum == 5 { scalar sc_eqyc = 6 } capture log close log using `outdatadir'\carbonnpv_valid_sp_`species'_`policyyear'.log, replace di "No Thin YC 20" if `speciesnum' != 5 { tabstat co2val_ha dtCO2_ag_mc dtCO2_bg_mc dtCO2_hwp_nir dtCO2_bg_ph dtCO2_tm_mc dtCO2_lf_mc dtCO2_hl_mc if yc == sc_eqyc & thin == 0, by(year) } di "Thin YC 20" tabstat co2val_ha dtCO2_ag_mc dtCO2_bg_mc dtCO2_hwp_nir dtCO2_bg_ph dtCO2_tm_mc dtCO2_lf_mc dtCO2_hl_mc if yc == sc_eqyc & thin == 1, by(year) log close ************************************************ * Background Tables ************************************************ use "`outdatadir'\ForestCarbonPanel2_`policyyear'.dta", clear capture log close log using `outdatadir'\BackgroundTabs`policyyear'.log, replace do "`dodir'\BackgroundTabs.do" log close *********************************************************************** * Save species specific *********************************************************************** *Oak if `species' == 5 { save "`outdatadir'\ForestCarbonPanel2Oak`policyyear'", replace } *Japanese Larch if `species' == 4 { save "`outdatadir'\ForestCarbonPanel2JL`policyyear'", replace } *Norway spruce if `species' == 2 { save "`outdatadir'\ForestCarbonPanel2NS`policyyear'", replace } *Sitka Spruce if `species' == 1 { save "`outdatadir'\ForestCarbonPanel2SS`policyyear'", replace } *BL if `species' == 0 { save "`outdatadir'\ForestCarbonPanel2BL`policyyear'", replace }
And I received this error.
Code:
. ********************************************** . * Forestry Distributional Analysis . ********************************************** . . use "`outdatadir'\ForestryNPV_`policyyear'.dta", clear 293. *Create YCEquiv (equivalent to SS) . *This is necessary to link to farms, where soil and associated yield class relate to sitka . qui do "`dodir'\DoYCEquiv.do" 294. sort ycequiv thin 295. save "`outdatadir'\ForestryNPV_`policyyear'.dta", replace 296. . use "`outdatadir'\farmaenpv_`policyyear'.dta", clear 297. capture gen ycequiv = yc 298. sort ycequiv thin 299. merge ycequiv thin using "`outdatadir'\ForestryNPV_`policyyear'.dta" 300. qui drop _merge 301. qui drop if FARM_CODE == . 302. . capture log close 303. log using `outdatadir'\ForestDistributionalAnalysis`policyyear'.log, replace 304. do "`dodir'\ForestDistributionalAnalysis.do 305. capture log close 306. save "`outdatadir'\FarmForestryNPV_`policyyear'.dta", replace 307. . ********************************************** . * Forestry Carbon Analysis . ********************************************** . use "`outdatadir'\FarmForestryNPV_`policyyear'.dta", clear 308. scalar sc_thin = 1 309. cap drop 310. capture log close 311. log using `outdatadir'\CarbonAnalysis_spec_`species'_`policyyear'.log, replace 312. do "`dodir'\CarbonAnalysis.do" 313. capture log close 314. save "`outdatadir'\FarmForestryCarbonNPV_`policyyear'.dta", replace 315. . ***NB Each File is double size as each farm as both thin and no thin*** . . *Oak . if `species' == 5 { 316. save "`outdatadir'\FarmForestryNPVCO2Oak`policyyear'", replace 317. } 318. *Lodge Pole Pine . if `species' == 3 { 319. save "`outdatadir'\FarmForestryNPVCO2LPN`policyyear'", replace 320. } 321. *Japanese Larch . if `species' == 4 { 322. save "`outdatadir'\FarmForestryNPVCO2JL`policyyear'", replace 323. } 324. *Norway spruce . if `species' == 2 { 325. save "`outdatadir'\FarmForestryNPVCO2NS`policyyear'", replace 326. } 327. *Sitka Spruce . if `species' == 1 { 328. save "`outdatadir'\FarmForestryNPVCO2SS`policyyear'", replace 329. } 330. *BL . if `species' == 0 { 331. save "`outdatadir'\FarmForestryNPVCO2BL`policyyear'", replace 332. } 333. summ yc thin age year dtCO2_ag_mc dtCO2_bg_mc dtCO2_hwp_nir dtCO2_bg_ph dtCO2_tm_mc dtCO2_hl_mc dtCO2_lf_mc 334. } variable yc not found r(111); . } r(111); end of do-file r(111); .
Comment