<s> """<STR_LIT>""" <EOL> from statsmodels . compat . python import range , lmap <EOL> import numpy as np <EOL> from numpy . testing import assert_almost_equal <EOL> from statsmodels . regression . linear_model import OLS <EOL> from statsmodels . tools . tools import add_constant <EOL> import statsmodels . stats . sandwich_covariance as sw <EOL> def test_panel_robust_cov ( ) : <EOL> import pandas as pa <EOL> import statsmodels . datasets . grunfeld as gr <EOL> from . results . results_panelrobust import results as res_stata <EOL> dtapa = gr . data . load_pandas ( ) <EOL> dtapa_endog = dtapa . endog [ : <NUM_LIT:200> ] <EOL> dtapa_exog = dtapa . exog [ : <NUM_LIT:200> ] <EOL> res = OLS ( dtapa_endog , add_constant ( dtapa_exog [ [ '<STR_LIT:value>' , '<STR_LIT>' ] ] , <EOL> prepend = False ) ) . fit ( ) <EOL> time = np . asarray ( dtapa_exog [ [ '<STR_LIT>' ] ] ) <EOL> time -= time . min ( ) <EOL> time = np . squeeze ( time ) . astype ( int ) <EOL> tidx = [ ( i * <NUM_LIT:20> , <NUM_LIT:20> * ( i + <NUM_LIT:1> ) ) for i in range ( <NUM_LIT:10> ) ] <EOL> firm_names , firm_id = np . unique ( np . asarray ( dtapa_exog [ [ '<STR_LIT>' ] ] , '<STR_LIT>' ) , <EOL> return_inverse = True ) <EOL> cov = sw . cov_nw_panel ( res , <NUM_LIT:0> , tidx , use_correction = '<STR_LIT>' ) <EOL> assert_almost_equal ( cov , res_stata . cov_pnw0_stata , decimal = <NUM_LIT:4> ) <EOL> cov = sw . cov_nw_panel ( res , <NUM_LIT:1> , tidx , use_correction = '<STR_LIT>' ) <EOL> assert_almost_equal ( cov , res_stata . cov_pnw1_stata , decimal = <NUM_LIT:4> ) <EOL> cov = sw . cov_nw_panel ( res , <NUM_LIT:4> , tidx ) <EOL> assert_almost_equal ( cov , res_stata . cov_pnw4_stata , decimal = <NUM_LIT:4> ) <EOL> cov_clu = sw . cov_cluster ( res , firm_id ) <EOL> assert_almost_equal ( cov_clu , res_stata . cov_clu_stata , decimal = <NUM_LIT:4> ) <EOL> cov_clu = sw . cov_cluster ( res , lmap ( str , firm_id ) ) <EOL> assert_almost_equal ( cov_clu , res_stata . cov_clu_stata , decimal = <NUM_LIT:4> ) <EOL> rcov = sw . cov_nw_groupsum ( res , <NUM_LIT:0> , time , use_correction = <NUM_LIT:0> ) <EOL> assert_almost_equal ( rcov , res_stata . cov_dk0_stata , decimal = <NUM_LIT:4> ) <EOL> rcov = sw . cov_nw_groupsum ( res , <NUM_LIT:1> , time , use_correction = <NUM_LIT:0> ) <EOL> assert_almost_equal ( rcov , res_stata . cov_dk1_stata , decimal = <NUM_LIT:4> ) <EOL> rcov = sw . cov_nw_groupsum ( res , <NUM_LIT:4> , time ) <EOL> assert_almost_equal ( rcov , res_stata . cov_dk4_stata , decimal = <NUM_LIT:4> ) </s>
