Beispiel #1
0
    def emax_bigt(self, bigT):
        """
		Computes the emax function for the last period (takes T-1 states, and 
			integrates period T unobservables)
		In this period, there is no choice of child care. So the are
		only five choices.


		bigT: indicates the last period (in calendar time)
		"""

        #dictionary with the grid
        #dict_aux=gridemax.grid()

        #Defining state variables of T-1
        passign = self.grid_dict['passign']
        theta0 = self.grid_dict['theta0']
        nkids0 = self.grid_dict['nkids0']
        married0 = self.grid_dict['married0']
        agech = self.grid_dict['agech']
        epsilon_1 = self.grid_dict['epsilon_1']  #initial shock

        x_w = self.grid_dict['x_w']
        x_m = self.grid_dict['x_m']
        x_k = self.grid_dict['x_k']
        x_wmk = self.grid_dict['x_wmk']

        #Sample size
        ngrid = theta0.shape[0]

        agech = np.reshape(agech, ngrid)
        #number of choices (hours worked * child care)
        J = 6

        #I save emaxT(T-1) values here
        emax_t1 = np.zeros((ngrid, J))

        #At T-1, possible choices
        hours = np.zeros(ngrid)
        childcare = np.zeros(ngrid)

        self.change_util(self.param, ngrid, x_w, x_m, x_k, passign, nkids0,
                         married0, hours, childcare, agech, self.hours_p,
                         self.hours_f, self.wr, self.cs, self.ws)
        wage0 = self.model.waget(bigT - 1, epsilon_1)
        free0 = self.model.q_prob()
        price0 = self.model.price_cc()

        #Choice T-1 loop
        for jt in range(0, J):
            if jt <= 2:
                if jt == 0:
                    hours_aux = 0
                elif jt == 1:
                    hours_aux = self.hours_p
                elif jt == 2:
                    hours_aux = self.hours_f
                hours = np.full(ngrid, hours_aux, dtype=float)
                childcare = np.zeros(ngrid)

            else:
                if jt == 3:
                    hours_aux = 0
                elif jt == 4:
                    hours_aux = self.hours_p
                elif jt == 5:
                    hours_aux = self.hours_f
                hours = np.full(ngrid, hours_aux, dtype=float)
                childcare = np.ones(ngrid)

            #Here I save array of Ut by schock/choice (at T)
            u_vec = np.zeros((ngrid, self.D, J))

            #Income and consumption at T-1
            dincome0 = self.model.dincomet(bigT - 1, hours, wage0, married0,
                                           nkids0)['income']
            consumption0 = self.model.consumptiont(bigT - 1, hours, childcare,
                                                   dincome0, married0, nkids0,
                                                   wage0, free0,
                                                   price0)['income_pc']

            #At T, loop over possible shocks, for every future choice
            #Montecarlo integration: loop over shocks by choice (hours and childcare)

            for j, i in itertools.product(range(0, J), range(0, self.D)):

                #States at T
                self.change_util(self.param, ngrid, x_w, x_m, x_k, passign,
                                 nkids0, married0, hours, childcare, agech,
                                 self.hours_p, self.hours_f, self.wr, self.cs,
                                 self.ws)

                periodt = bigT

                married_t1 = self.model.marriaget(periodt, married0)
                married_t1 = np.reshape(married_t1, (ngrid, 1))
                nkids_t1 = self.model.kidst(
                    periodt, np.reshape(nkids0, (ngrid, 1)), married0) + nkids0
                epsilon_t1 = self.model.epsilon(epsilon_1)
                wage_t1 = self.model.waget(periodt, epsilon_t1)
                free_t1 = self.model.q_prob()
                price_t1 = self.model.price_cc()
                #using t-1 income to get theta_T

                theta_t1 = self.model.thetat(
                    periodt - 1, theta0, hours, childcare,
                    consumption0)  #theta at t+1 uses inputs at t

                #future (at T) possible decision
                if j <= 2:
                    if j == 0:
                        hours_aux2 = 0
                    elif j == 1:
                        hours_aux2 = self.hours_p
                    elif j == 2:
                        hours_aux2 == self.hours_f
                    hours_t1 = np.full(ngrid, hours_aux2, dtype=float)
                    childcare_t1 = np.zeros(ngrid)
                else:
                    if j == 3:
                        hours_aux2 = 0
                    elif j == 4:
                        hours_aux2 = self.hours_p
                    elif j == 5:
                        hours_aux2 == self.hours_f
                    hours_t1 = np.full(ngrid, hours_aux2, dtype=float)
                    childcare_t1 = np.ones(ngrid)

                self.change_util(self.param, ngrid, x_w, x_m, x_k, passign,
                                 nkids_t1, married_t1, hours_t1, childcare,
                                 agech, self.hours_p, self.hours_f, self.wr,
                                 self.cs, self.ws)

                #This is the terminal value!
                u_vec[:, i, j] = self.model.simulate(
                    bigT, wage_t1, free_t1, price_t1,
                    theta_t1)  #Last period is T=8. Terminal value=0

            #obtaining max over choices by random schocks: young vs old
            max_ut = np.max(u_vec, axis=2)  #young

            #This is the emax for a given (for a given at choice T-1)
            av_max_ut = np.average(max_ut, axis=1)

            #database for interpolation
            data_int = np.concatenate(
                (
                    np.reshape(np.log(theta0), (ngrid, 1)),
                    np.reshape(nkids0, (ngrid, 1)),
                    np.reshape(married0, (ngrid, 1)),
                    np.reshape(np.square(np.log(theta0)), (ngrid, 1)),
                    np.reshape(passign, (ngrid, 1)),
                    np.reshape(epsilon_1, (ngrid, 1)),  #using present shock
                    np.reshape(np.square(epsilon_1), (ngrid, 1)),
                    x_wmk),
                axis=1)

            #Saving in the big matrix
            emax_t1[:, jt] = av_max_ut

            #saving instances.
            if jt == 0:
                emax_inst = [int_linear.Int_linear(data_int, av_max_ut)]
            else:
                emax_inst.append(int_linear.Int_linear(data_int, av_max_ut))

        #the instance with the eitc function and emax values

        return [emax_inst, emax_t1]
Beispiel #2
0
    def emax_t(self, periodt, bigt, emax_t1_ins):
        """
		Computes the emax function at period t<T, taking as input
		an interpolating instance at t+1	
		bigt: indicates the number of the final period 
		periodt indicate the period to compute emax (emax1,emax2,emax3,...)
		"""
        #dictionary with the grid
        #dict_aux=gridemax.grid()

        #Defining state variables at t-1
        passign = self.grid_dict['passign']
        theta0 = self.grid_dict['theta0']
        nkids0 = self.grid_dict['nkids0']
        married0 = self.grid_dict['married0']
        agech = self.grid_dict['agech']
        epsilon_1 = self.grid_dict['epsilon_1']  #initial shock

        x_w = self.grid_dict['x_w']
        x_m = self.grid_dict['x_m']
        x_k = self.grid_dict['x_k']
        x_wmk = self.grid_dict['x_wmk']

        #Sample size
        ngrid = theta0.shape[0]

        agech = np.reshape(agech, ngrid)

        #Set number of choices at t-1
        Jt = 6

        hours = np.zeros(ngrid)
        childcare = np.zeros(ngrid)

        self.change_util(self.param, ngrid, x_w, x_m, x_k, passign, nkids0,
                         married0, hours, childcare, agech, self.hours_p,
                         self.hours_f, self.wr, self.cs, self.ws)
        wage0 = self.model.waget(periodt, epsilon_1)
        free0 = self.model.q_prob()
        price0 = self.model.price_cc()

        #I save interpolating instances here
        emax_inst = []
        #I save emaxT(T-1) here
        emax_t1 = np.zeros((ngrid, Jt))

        #Loop: choice at t-1

        for jt in range(0, Jt):

            #choices at t-1
            if jt <= 2:
                if jt == 0:
                    hours_aux = 0
                elif jt == 1:
                    hours_aux = self.hours_p
                elif jt == 2:
                    hours_aux = self.hours_f

                hours = np.full(ngrid, hours_aux, dtype=float)
                childcare = np.zeros(ngrid)

            else:
                if jt == 3:
                    hours_aux = 0
                elif jt == 4:
                    hours_aux = self.hours_p
                elif jt == 5:
                    hours_aux = self.hours_f

                hours = np.full(ngrid, hours_aux, dtype=float)
                childcare = np.ones(ngrid)

            #I get these to compute theta_t1
            dincome0 = self.model.dincomet(periodt - 1, hours, wage0, married0,
                                           nkids0)['income']
            consumption0 = self.model.consumptiont(periodt - 1, hours,
                                                   childcare, dincome0,
                                                   married0, nkids0, wage0,
                                                   free0, price0)['income_pc']

            J = 6  #number of choides in the inner loop

            #Here I save array of Ut by schock/choice (at T)
            u_vec = np.zeros((ngrid, self.D, J))

            #Montecarlo integration: loop over shocks by choice at t (hours and childcare)
            for j, i in itertools.product(range(0, J), range(0, self.D)):
                #for i in range(0,D):

                #Computing states at t
                self.change_util(self.param, ngrid, x_w, x_m, x_k, passign,
                                 nkids0, married0, hours, childcare, agech,
                                 self.hours_p, self.hours_f, self.wr, self.cs,
                                 self.ws)

                married_t1 = self.model.marriaget(periodt, married0)
                married_t1 = np.reshape(married_t1, (ngrid, 1))
                nkids_t1 = self.model.kidst(
                    periodt, np.reshape(nkids0, (ngrid, 1)), married0
                ) + nkids0  #previous kids + if they have a kid next period
                epsilon_t1 = self.model.epsilon(epsilon_1)
                wage_t1 = self.model.waget(periodt, epsilon_t1)
                free_t1 = self.model.q_prob()
                price_t1 = self.model.price_cc()
                #income at t-1 to compute theta_t
                theta_t1 = self.model.thetat(
                    periodt - 1, theta0, hours, childcare,
                    consumption0)  #theta at t+1 uses inputs at t

                # Possible decision at t
                if j <= 2:
                    if j == 0:
                        hours_aux = 0
                    elif j == 1:
                        hours_aux = self.hours_p
                    elif j == 2:
                        hours_aux = self.hours_f
                    hours_t1 = np.full(ngrid, hours_aux, dtype=float)
                    childcare_t1 = np.zeros(ngrid)
                else:
                    if j == 3:
                        hours_aux = 0
                    elif j == 4:
                        hours_aux = self.hours_p
                    elif j == 5:
                        hours_aux = self.hours_f
                    hours_t1 = np.full(ngrid, hours_aux, dtype=float)
                    childcare_t1 = np.ones(ngrid)

                #Instance at period t
                self.change_util(self.param, ngrid, x_w, x_m, x_k, passign,
                                 nkids_t1, married_t1, hours_t1, childcare_t1,
                                 agech, self.hours_p, self.hours_f, self.wr,
                                 self.cs, self.ws)

                #Current-period utility at t
                u_vec[:, i, j] = self.model.simulate(periodt, wage_t1, free_t1,
                                                     price_t1, theta_t1)

                #getting next-period already computed emaxt+1
                data_int_ex = np.concatenate(
                    (np.reshape(np.log(theta_t1),
                                (ngrid, 1)), np.reshape(nkids_t1, (ngrid, 1)),
                     np.reshape(married_t1, (ngrid, 1)),
                     np.reshape(np.square(np.log(theta_t1)),
                                (ngrid, 1)), np.reshape(passign, (ngrid, 1)),
                     np.reshape(epsilon_t1, (ngrid, 1)),
                     np.reshape(np.square(epsilon_t1), (ngrid, 1)), x_wmk),
                    axis=1)

                #
                #obtaining emaxT+1
                #Emax instance of t+1 for choice j
                emax_inst_choice = emax_t1_ins[j]
                betas_t1_choice = emax_inst_choice.betas()
                emax_t1_choice = emax_inst_choice.int_values(
                    data_int_ex, betas_t1_choice)

                #Value function at t.
                u_vec[:, i, j] = u_vec[:, i, j] + 0.86 * emax_t1_choice

            #obtaining max over choices by random shock/choice at t-1. Young vs old
            max_ut = np.max(u_vec, axis=2)  #young

            #This is the emax for a given choice at t-1
            av_max_ut = np.average(max_ut, axis=1)

            #Data for interpolating emaxt (states at t-1)
            data_int = np.concatenate(
                (
                    np.reshape(np.log(theta0), (ngrid, 1)),
                    np.reshape(nkids0, (ngrid, 1)),
                    np.reshape(married0, (ngrid, 1)),
                    np.reshape(np.square(np.log(theta0)), (ngrid, 1)),
                    np.reshape(passign, (ngrid, 1)),
                    np.reshape(epsilon_1, (ngrid, 1)),  #current period shock
                    np.reshape(np.square(epsilon_1), (ngrid, 1)),
                    x_wmk),
                axis=1)

            #Emax value for a given choice
            emax_t1[:, jt] = av_max_ut

            #saving instances

            if jt == 0:
                emax_inst = [int_linear.Int_linear(data_int, av_max_ut)]
            else:
                emax_inst.append(int_linear.Int_linear(data_int, av_max_ut))

        #the instance with the eitc function and emax values

        return [emax_inst, emax_t1]
Beispiel #3
0
    def choice(self, periodt, bigt, theta0, nkids0, married0, wage0, epsilon0,
               free0, price0, spouse_income0, spouse_employment0):
        """
		Takes a set of state variables and computes the utility +option value
		of different set of choices for a given periodt

		These state variables do not change with period (set them equal at t=0):
		x_w,x_m,x_k,passign. The rest of the state variables change according to
		the period

		It returns a list containing the utility value and the emaxt+1 that is 
		computed in period t

		epsilon 0: shock consistent with wage0


		"""

        #Set number of choices
        J = 3 * 2

        #save choices utility  here
        util_values = np.zeros((self.N, J))
        #save current value here
        util_values_c = np.zeros((self.N, J))

        hours_aux = [
            0, self.hours_p, self.hours_f, 0, self.hours_p, self.hours_f
        ]

        cc_aux = [0, 0, 0, 1, 1, 1]

        for j in range(0, J):

            hours = np.full(self.N, hours_aux[j], dtype=float)
            childcare = np.full(self.N, cc_aux[j], dtype=float)

            #Computing utility
            self.change_util(self.param, self.N, self.x_w, self.x_m, self.x_k,
                             self.passign, nkids0, married0, hours, childcare,
                             self.agech, self.hours_p, self.hours_f, self.wr,
                             self.cs, self.ws)

            #current consumption to get future theta
            dincome0 = self.model.dincomet(periodt, hours, wage0, married0,
                                           nkids0, spouse_income0,
                                           spouse_employment0)['income']
            consumption0 = self.model.consumptiont(periodt, hours, childcare,
                                                   dincome0, spouse_income0,
                                                   spouse_employment0,
                                                   married0, nkids0, wage0,
                                                   free0, price0)['income_pc']

            util_values[:,
                        j] = self.model.simulate(periodt, wage0, free0, price0,
                                                 theta0, spouse_income0,
                                                 spouse_employment0)
            util_values_c[:, j] = util_values[:, j]

            ####Only for periods t<T (compute an emax function)
            #For period T, only current utility
            if periodt < bigt:
                #Data for computing emaxt+1, given choices and state at t
                married_t1 = self.model.marriaget(periodt + 1, married0)
                married_t1 = np.reshape(married_t1, (self.N, 1))
                nkids_t1 = self.model.kidst(
                    periodt + 1, np.reshape(nkids0,
                                            (self.N, 1)), married0) + nkids0

                theta_t1 = self.model.thetat(
                    periodt, theta0, hours, childcare,
                    consumption0)  #theta at t+1 uses inputs at t
                epsilon_t1 = self.model.epsilon(epsilon0)

                data_int_t1 = np.concatenate(
                    (np.reshape(np.log(theta_t1),
                                (self.N, 1)), np.reshape(
                                    nkids_t1, (self.N, 1)), married_t1,
                     np.reshape(np.square(np.log(theta_t1)), (self.N, 1)),
                     np.reshape(self.passign, (self.N, 1)),
                     np.reshape(epsilon_t1, (self.N, 1)),
                     np.reshape(np.square(epsilon_t1),
                                (self.N, 1)), self.x_wmk),
                    axis=1)

                #arbitrary initializacion
                emax_ins = int_linear.Int_linear()

                #Getting dictionary to incorporate emax_t+1, choice j
                for age in range(1, 11):

                    #from this age, individuals solve a shorter problem
                    if age >= 2:
                        if periodt + 1 >= 19 - age:
                            emax_t1 = np.zeros(self.N)
                        else:
                            emax_betas = self.emax_function[10 - age][0][
                                'emax' + str(periodt + 1)][j]
                            emax_t1 = emax_ins.int_values(
                                data_int_t1, emax_betas)

                    else:
                        emax_betas = self.emax_function[10 -
                                                        age][0]['emax' +
                                                                str(periodt +
                                                                    1)][j]
                        emax_t1 = emax_ins.int_values(data_int_t1, emax_betas)

                    #Including option value (discount factor 0.86), youngest child
                    util_values[self.agech[:, 0] == age, j] = util_values[
                        self.agech[:, 0] == age,
                        j] + 0.86 * emax_t1[self.agech[:, 0] == age]

        return [util_values, util_values_c]
Beispiel #4
0
	def emax_bigt(self,bigT):
		"""
		Computes the emax function for the last period (takes T-1 states, and 
			integrates period T unobservables)
		In this period, there is no choice of child care. So the are
		only five choices.


		bigT: indicates the last period (in calendar time)
		"""

		#dictionary with the grid
		#dict_aux=gridemax.grid()

		#Defining state variables of T-1
		passign=self.grid_dict['passign']
		theta0=self.grid_dict['theta0'][:,0]
		nkids0=self.grid_dict['nkids0']
		married0=self.grid_dict['married0']
		agech=self.grid_dict['agech']
		epsilon_1=self.grid_dict['epsilon_1'][:,0]#initial shock
		

		x_w=self.grid_dict['x_w']
		x_m=self.grid_dict['x_m']
		x_k=self.grid_dict['x_k']
		x_wmk=self.grid_dict['x_wmk']



		#Sample size
		ngrid=theta0.shape[0]
		agech=np.reshape(agech,ngrid)
		#number of choices (hours worked * child care 1,2)
		J=3*2

		#I save emaxT(T-1) values here
		emax_t1=np.zeros((ngrid,J))

		#At T-1, possible choices
		hours=np.zeros(ngrid)
		childcare=np.zeros(ngrid)

		self.change_util(self.param,ngrid,x_w,x_m,x_k,passign,
			nkids0,married0,hours,childcare,agech,self.hours_p,self.hours_f,
			self.wr,self.cs,self.ws)
		wage0=self.model.waget(bigT-1,epsilon_1)
		free0=self.model.q_prob()
		price0=self.model.price_cc()

		list_hours = [0,self.hours_p,self.hours_f]
		list_cc = [0,1]
		
		#choices: j, types of choice.
		list_choice = [[[list_hours[i],list_cc[j]] 
					for i in range(0,3)] for j in range(0,2)]

		hours_aux  = [0,self.hours_p,self.hours_f,
					0,self.hours_p,self.hours_f]

		cc_aux  = [0,0,0,
					1,1,1]

		#Choice T-1 loop
		for jt in range(0,J):

			hours = np.full(ngrid,hours_aux[jt],dtype=float)
			childcare = np.full(ngrid,cc_aux[jt],dtype=float)
						
			#Here I save array of Ut by schock/choice (at T)
			u_vec=np.zeros((ngrid,self.D,J))

			#Income and consumption at T-1
			spouse_income = self.model.income_spouse()
			employment_spouse = self.model.employment_spouse()
			dincome0=self.model.dincomet(bigT-1,hours,wage0,married0,nkids0,spouse_income,employment_spouse)['income']
			consumption0=self.model.consumptiont(bigT-1,hours,childcare,
				dincome0,spouse_income,employment_spouse,
				married0,nkids0,wage0,free0,price0)['income_pc']
			

			#At T, loop over possible shocks, for every future choice
			#Montecarlo integration: loop over shocks by choice (hours and childcare)
					
			#for j,i in itertools.product(range(0,J),range(0,self.D)):

			for j in range(J):
				for i in range(self.D):
				

					#States at T
					self.change_util(self.param,ngrid,x_w,x_m,x_k,
						passign,nkids0,married0,hours,childcare,agech,self.hours_p,self.hours_f,self.wr,self.cs,self.ws)

					periodt=bigT 

					married_t1=self.model.marriaget(periodt,married0)
					married_t1=np.reshape(married_t1,(ngrid,1))
					nkids_t1=self.model.kidst(periodt,np.reshape(nkids0,(ngrid,1)),
						married0)+nkids0
					epsilon_t1 = self.model.epsilon(epsilon_1)
					wage_t1=self.model.waget(periodt,epsilon_t1)
					free_t1=self.model.q_prob()
					price_t1=self.model.price_cc()
					income_spouse_t1=self.model.income_spouse()
					employment_spouse_t1=self.model.employment_spouse()
					#using t-1 income to get theta_T
					
					theta_t1=self.model.thetat(periodt-1,theta0,hours,childcare,consumption0) #theta at t+1 uses inputs at t

					#future (at T) possible decision
					hours_t1 = np.full(ngrid,hours_aux[j],dtype=float)
					childcare_t1 = np.full(ngrid,cc_aux[j],dtype=float)
					
					self.change_util(self.param,ngrid,x_w,x_m,x_k,
						passign,nkids_t1,married_t1,hours_t1,childcare_t1,
						agech,
						self.hours_p,self.hours_f,self.wr,self.cs,self.ws)
					
					#This is the terminal value!
					u_vec[:,i,j]=self.model.simulate(bigT,wage_t1,free_t1,price_t1,theta_t1,
					income_spouse_t1,employment_spouse_t1) #Last period is T=8. Terminal value=0

				


			#obtaining max over choices by random schocks.
			max_ut=np.zeros((ngrid,self.D))
			max_ut[agech<=5,:]=np.max(u_vec[agech<=5,:,:],axis=2) #young
			max_ut[agech>5,:]=np.max(u_vec[agech>5,:,0:3],axis=2) #old


			#This is the emax for a given (for a given at choice T-1)
			av_max_ut=np.average(max_ut,axis=1)

			#database for interpolation
			data_int=np.concatenate( ( np.reshape(np.log(theta0),(ngrid,1)),
				np.reshape(nkids0,(ngrid,1)),np.reshape(married0,(ngrid,1)),
				np.reshape(np.square(np.log(theta0)),(ngrid,1)),
				np.reshape(passign,(ngrid,1)), 
				np.reshape(epsilon_1,(ngrid,1)),#using present shock
				np.reshape(np.square(epsilon_1),(ngrid,1)),
				x_wmk ), axis=1)

			#saving betas for emax computation
			if jt==0:
				emax_inst=[int_linear.Int_linear().betas(data_int,av_max_ut)]
			else:
				emax_inst.append(int_linear.Int_linear().betas(data_int,av_max_ut))

			

					
			

		#the instance with the eitc function and emax values

		return [emax_inst]
Beispiel #5
0
	def emax_t(self,periodt,bigt,emax_t1_betas):
		"""
		Computes the emax function at period t<T, taking as input
		an interpolating instance at t+1	
		bigt: indicates the number of the final period 
		periodt indicate the period to compute emax (emax1,emax2,emax3,...)
		"""
		#dictionary with the grid
		#dict_aux=gridemax.grid()

		#Defining state variables at t-1
		passign = self.grid_dict['passign']
		theta0 = self.grid_dict['theta0'][:,0]
		nkids0 = self.grid_dict['nkids0']
		married0 = self.grid_dict['married0']
		agech = self.grid_dict['agech']
		
		epsilon_1 = self.grid_dict['epsilon_1'][:,0]#initial shock
		

		x_w = self.grid_dict['x_w']
		x_m = self.grid_dict['x_m']
		x_k = self.grid_dict['x_k']
		x_wmk = self.grid_dict['x_wmk']

		
		#Sample size
		ngrid = theta0.shape[0]

		agech = np.reshape(agech,ngrid)
				
		#Set number of choices at t-1
		Jt = 3*2

		hours=np.zeros(ngrid)
		childcare=np.zeros(ngrid)
		
		self.change_util(self.param,ngrid,x_w,x_m,x_k,passign,
			nkids0,married0,hours,childcare,agech,
			self.hours_p,self.hours_f,self.wr,self.cs,self.ws)
		wage0 = self.model.waget(periodt,epsilon_1)
		free0 = self.model.q_prob()
		price0 = self.model.price_cc()


		#I save interpolating instances here
		emax_inst=[]
		#I save emaxT(T-1) here
		emax_t1=np.zeros((ngrid,Jt))

		hours_aux  = [0,self.hours_p,self.hours_f,
					0,self.hours_p,self.hours_f]

		cc_aux  = [0,0,0,
					1,1,1]
	
		#Loop: choice at t-1
		
		for jt in range(0,Jt):
						
			hours = np.full(ngrid,hours_aux[jt],dtype=float)
			childcare = np.full(ngrid,cc_aux[jt],dtype=float)
			
			#I get these to compute theta_t1
			spouse_income0 = self.model.income_spouse()
			spouse_employment0 = self.model.employment_spouse()
			dincome0=self.model.dincomet(periodt-1,hours,wage0,married0,nkids0,
				spouse_income0,spouse_employment0)['income']
			consumption0=self.model.consumptiont(periodt-1,hours,childcare,
				dincome0,spouse_income0,spouse_employment0,
				married0,nkids0,wage0,free0,price0)['income_pc']
			

			J=3*2 #number of choides in the inner loop

			#Here I save array of Ut by schock/choice (at T)
			u_vec=np.zeros((ngrid,self.D,J))
			

			#Montecarlo integration: loop over shocks by choice at t (hours and childcare)

			for j in range(J):
				for i in range(self.D):
			
								
					#Computing states at t
					self.change_util(self.param,ngrid,x_w,x_m,x_k,
						passign,nkids0,married0,hours,childcare,agech,
						self.hours_p,self.hours_f,self.wr,self.cs,self.ws)
					
					
					married_t1 = self.model.marriaget(periodt,married0)
					married_t1 = np.reshape(married_t1,(ngrid,1))
					nkids_t1 = self.model.kidst(periodt,np.reshape(nkids0,(ngrid,1)),
						married0)+nkids0 #previous kids + if they have a kid next period
					epsilon_t1 = self.model.epsilon(epsilon_1)
					wage_t1 = self.model.waget(periodt,epsilon_t1)
					free_t1 = self.model.q_prob()
					price_t1 = self.model.price_cc()
					income_spouse_t1 = self.model.income_spouse()
					employment_spouse_t1 = self.model.employment_spouse()
					#income at t-1 to compute theta_t
					theta_t1 = self.model.thetat(periodt-1,theta0,hours,childcare,consumption0) #theta at t+1 uses inputs at t

					# Possible decision at t
					hours_t1 = np.full(ngrid,hours_aux[j],dtype=float)
					childcare_t1 = np.full(ngrid,cc_aux[j],dtype=float)
										
					#Instance at period t
					self.change_util(self.param,ngrid,x_w,x_m,x_k,
						passign,nkids_t1,married_t1,hours_t1,childcare_t1,
						agech,
						self.hours_p,self.hours_f,self.wr,self.cs,self.ws)

					#Current-period utility at t
					u_vec[:,i,j]=self.model.simulate(periodt,wage_t1,free_t1,price_t1,
						theta_t1,income_spouse_t1,employment_spouse_t1) 

					#getting next-period already computed emaxt+1
					data_int_ex=np.concatenate(( np.reshape(np.log(theta_t1),(ngrid,1)),
						np.reshape(nkids_t1,(ngrid,1)),np.reshape(married_t1,(ngrid,1)),
						np.reshape(np.square(np.log(theta_t1)),(ngrid,1)),
						np.reshape(passign,(ngrid,1)), 
						np.reshape(epsilon_t1,(ngrid,1)),
						np.reshape(np.square(epsilon_t1),(ngrid,1)),
						x_wmk ), axis=1)

					#betas and data for extrapolation
					emax_inst_choice = int_linear.Int_linear()
					emax_t1_choice=emax_inst_choice.int_values(data_int_ex,emax_t1_betas[j])

					#Value function at t.
					u_vec[:,i,j]=u_vec[:,i,j]+0.86*emax_t1_choice

				
			#obtaining max over choices by random shock/choice at t-1. Young vs old
			max_ut=np.zeros((ngrid,self.D))
			max_ut[agech<=5,:]=np.max(u_vec[agech<=5,:,:],axis=2) #young
			max_ut[agech>5,:]=np.max(u_vec[agech>5,:,0:3],axis=2) #old


			#This is the emax for a given choice at t-1
			av_max_ut=np.average(max_ut,axis=1)

			#Data for interpolating emaxt (states at t-1)
			#if child A/B is not present, log theta_a/b is zero
			data_int=np.concatenate(( np.reshape(np.log(theta0),(ngrid,1)),
				np.reshape(nkids0,(ngrid,1)),np.reshape(married0,(ngrid,1)),
				np.reshape(np.square(np.log(theta0)),(ngrid,1)),
				np.reshape(passign,(ngrid,1)), 
				np.reshape(epsilon_1,(ngrid,1)),#current period shock
				np.reshape(np.square(epsilon_1),(ngrid,1)),
				x_wmk ), axis=1)

			
			#saving instances

			if jt==0:
				emax_inst=[int_linear.Int_linear().betas(data_int,av_max_ut)]
			else:
				emax_inst.append(int_linear.Int_linear().betas(data_int,av_max_ut))





		#the instance with the eitc function
		return [emax_inst]
Beispiel #6
0
    (np.reshape(np.log(theta0_a),
                (N, 1)), np.reshape(np.log(theta0_b),
                                    (N, 1)), nkids0, married0,
     np.reshape(np.square(np.log(theta0_a)),
                (N, 1)), np.reshape(np.square(np.log(theta0_b)),
                                    (N, 1)), passign,
     np.reshape(epsilon0, (N, 1)), np.reshape(np.square(epsilon0),
                                              (N, 1)), x_wmk),
    axis=1)

#take emax of the youngest possible child
#this is the interpolated emax values
emax_t1_int = np.zeros((N, J))
for j in range(J):
    emax_betas = emax_dic_true[8][0]['emax1'][j].copy()
    emax_ins = int_linear.Int_linear()  #arbitrary initializacion
    emax_t1_int[:, j] = emax_ins.int_values(data_int_ex, emax_betas)

#The true emax values (these are the value used for computing interpolation )
#true_grid = { 'passign': dict_grid['passign'],'theta0': dict_grid['theta0'],
#	 'nkids0': dict_grid['nkids0'] , 'married0': dict_grid['married0'],
#		'x_w': dict_grid['x_w'], 'x_m':dict_grid['x_m'],
#		'x_k': dict_grid['x_k'], 'x_wmk': dict_grid['x_wmk'],
#		'agech':dict_grid['agech'],
#		'epsilon_1': dict_grid['epsilon_1'] }

#emax_function_in_true = emax.Emaxt(param0,D,true_grid,hours_p,hours_f,wr,cs,ws,model)
#emax_dic_true = emax_function_in_true.recursive()
#emax_t1_true = emax_dic_true[9][1]['emax1'] #(ngrid,n_choices)

######################################################################