I am trying, with the following loop to drop some of my observations, specifically the ones that have quarters below the molecule with the highest quarter and the ones that have quarters above the molecule with the lowest quarter (so if I have mol1 appearing from 2012Q3 and mol2 ending in 2015q3 and other molecules ranging from 2009q3 to 2020q3 I would like to keep only observations from 2012q3 to 2015q3):
Code:
quietly drop if trimestre < `min' | trimestre > `max'
Code:
use "/Users/federiconutarelli/Dropbox/PhD/Elasticities/2008_2020_db/dati_per_paese/2008_2020_prd.dta", clear drop if Country =="ITALY" levelsof Countr, local(levels) foreach l of local levels { use "/Users/federiconutarelli/Dropbox/PhD/Elasticities/2008_2020_db/dati_per_paese/data_ctry/`l'_new.dta", clear quietly levelsof Mole, local(molecules) foreach k of local molecules { local rex = strtoname("`k'") use "/Users/federiconutarelli/Desktop/here/`l'/`rex'.dta", clear gen price = sales/stdunits gen ln_price=ln(price) gen ln_stdunits = ln(stdunits) quietly sum panelsize local min_panelsize = r(min) sum trimestre if panelsize == `min_panelsize' local min = r(min) local max = r(max) quietly drop if trimestre < `min' | trimestre > `max' quietly drop panels* bysort id_prd id_mole: gen panelsize = _N save "/Users/federiconutarelli/Desktop/here/`l'/`rex'.dta",replace } }
Is there something wrong I am doing here?
Thank you,
Federico
0 Response to Strange macro behaviour
Post a Comment