Z = np.column_stack((np.ones(nobs_i), Z))

        noise = 0.1 * np.random.randn(nobs_i)  #sig_e = 0.1

        #generate endogenous variable
        Y = np.dot(X, beta) + np.dot(Z, gamma_re) + noise

        #add random effect design matrix also to fixed effects to
        #capture the mean
        #this seems to be necessary to force mean of RE to zero !?
        #(It's not required for estimation but interpretation of random
        #effects covariance matrix changes - still need to check details.
        X = np.hstack((X, Z))

        #create units and append to list
        unit = Unit(Y, X, Z)
        units.append(unit)

    m = OneWayMixed(units)

    import time
    t0 = time.time()
    m.initialize()
    res = m.fit(maxiter=100, rtol=1.0e-5, params_rtol=1e-6, params_atol=1e-6)
    t1 = time.time()
    print 'time for initialize and fit', t1 - t0
    print 'number of iterations', m.iterations
    #print dir(m)
    #print vars(m)
    print '\nestimates for fixed effects'
    print m.a
Esempio n. 2
0
        noise = 0.1 * np.random.randn(nobs_i)  #sig_e = 0.1

        #generate endogenous variable
        Y = np.dot(X, beta) + np.dot(Z, gamma_re) + noise

        #add random effect design matrix also to fixed effects to
        #capture the mean
        #this seems to be necessary to force mean of RE to zero !?
        #(It's not required for estimation but interpretation of random
        #effects covariance matrix changes - still need to check details.
        #X = np.hstack((X,Z))
        X = np.hstack((X, time_dummies))

        # create units and append to list
        new_unit = Unit(Y, X, Z)
        units.append(new_unit)

    m = OneWayMixed(units)

    import time
    t0 = time.time()
    m.initialize()
    res = m.fit(maxiter=100, rtol=1.0e-5, params_rtol=1e-6, params_atol=1e-6)
    t1 = time.time()
    print('time for initialize and fit', t1 - t0)
    print('number of iterations', m.iterations)
    #print dir(m)
    #print vars(m)
    print('\nestimates for fixed effects')
    print(m.a)