global up "D:\Analisis\12.
Planilla\Bases etiquetas"
global save "D:\Diarios y mensuales\Pedidos puntuales\7. Subsidio independeintes y
planilla\Seguimiento al Diseño de Subsidio\Enero 2021_actualizando SUNAT\Insumos"
global base "D:\Diarios y mensuales\Pedidos puntuales\7. Subsidio independeintes y
planilla\Seguimiento al Diseño de Subsidio\Enero 2021_actualizando SUNAT"
global sunat "D:\Diarios y mensuales\Pedidos puntuales\10. Base Sunat\Base Junio y
Julio 2020"
*use id* v_numperiod v_codsec using "$up\\2020 meses\Priv_202001",clear
global vars edad n_monperman v_codtipcon_it regla v_codsec v_estreglabt_it
c_codpainac_3
forvalues year = 2015/2021{
foreach fecha in `year'01 `year'02 `year'03 `year'04 `year'05 `year'06 `year'07
`year'08 `year'09 `year'10 `year'11 `year'12 {
*local fecha 202004
*local year 2020
display "`fecha'"
use id_empresa id_trabajador v_numperiod $vars using "$up\\`year' meses\
Priv_`fecha'.dta",clear
foreach x of varlist $vars {
ren `x' `x'1
}
local next=`fecha'+1
if `next'==`year'13 {
local year=`year'+1
local next=`year'01
}
merge 1:1 id_empresa id_trabajador using "$up\\`year' meses\
Priv_`next'.dta",gen(perm) keepusing(id_empresa id_trabajador $vars)
replace v_numperiod="`next'"
foreach x of varlist $vars {
replace `x'1=`x' if perm==2
drop `x'
ren `x'1 `x'
}
lab def perm 1 "Salidas" 2 "Entradas" 3 "Permanencia",replace
lab val perm perm
recode edad (min/17=1 "Hasta 17 años")(18/24=2 "De 18 a 24 años")(25/29=3 "De
25 a 29 años")(30/59=4 "De 30 a 59 años")(60/max=5 "De 60 a más")(else=6 "No
determinado"),gen(gedad)
lab var gedad "Rangos de edad del trabajador"
gen remunerac=1 if n_monperman<=1500
replace remunerac=2 if n_monperman>1500 & n_monperman<=2400
replace remunerac=3 if n_monperman>2400
lab var remunerac "Rangos de remunerac"
label def remunerac 1 "hasta 1500" 2 "mayor 1500 hasta 2400" 3 "mayor
2400",replace
label val remunerac remunerac
merge m:1 id_empresa using "$base\
Subsidio_MTPE_Ingresos_20210318.dta",gen(sunat)
keep if sunat==3
gen x= 1
recode v_codtipcon_it(1=1 "[Link]")(10 9 4 3=2 "[Link]")(else=3
"Otros"),gen(contrato)
recode v_estreglabt_it(1=1 "[Link] 728")(1/99=2 "Otro")(else=3
"ND"),gen(regimen)
// ultimos filtros
merge m:1 id_empresa using "$save\Base_octubre.dta",gen(m1)
drop if m1==2
recode m1(3=1 "Emp Oct")(1 2=0 "Otros"),gen(oct)
destring c_codpainac_3,replace
keep if c_codpainac_3==9589 // nacionales
drop if edad==. | edad<=17 // sin edad
drop if n_monperman==0 // sin remuneracion
collapse (sum) x,by( oct v_estreglabt_it gedad perm remunerac contrato
v_codsec regimen v_numperiod)
saveold "$save\base`next'.dta",replace
}
}
use "$save\[Link]",clear
forvalues year = 2015/2021 {
foreach fecha in `year'01 `year'02 `year'03 `year'04 `year'05 `year'06
`year'07 `year'08 `year'09 `year'10 `year'11 `year'12 {
if `fecha'>=201503 {
display "`fecha'"
append using "$save\base`fecha'.dta"
}
}
}
*TABULADOS DE ENTRADAS Y SALIDAS
tab v_numperiod perm [iw=x]
tab gedad v_numperiod [iw=x] if perm==1
tab gedad v_numperiod [iw=x] if perm==2
// (bi_abr_may>=4 & bi_abr_may<=6)
*Entradas
table gedad v_numperiod [iw=x] if perm==2 & remunerac<=2 & contrato==1 &
gedad==2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==2 & remunerac<=2 & contrato==1 & gedad!
=2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==2 & remunerac<=2 & contrato==2 &
gedad==2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==2 & remunerac<=2 & contrato==2 & gedad!
=2,format(%5,0f) row
*Salidas
table gedad v_numperiod [iw=x] if perm==1 & remunerac<=2 & contrato==1 &
gedad==2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==1 & remunerac<=2 & contrato==1 & gedad!
=2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==1 & remunerac<=2 & contrato==2 &
gedad==2,format(%5,0f) row
table gedad v_numperiod [iw=x] if perm==1 & remunerac<=2 & contrato==2 & gedad!
=2,format(%5,0f) row
*EXPORTAR
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==2 & remunerac<=2 &
contrato==2 & gedad==2,dpcomma f(4) replace clab(18_24Entrada)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==2 & remunerac<=2 &
contrato==2 & gedad!=2,dpcomma f(4) append clab(25_masEntrada)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==1 & remunerac<=2 &
contrato==2 & gedad==2,dpcomma f(4) append clab(18_24Salida)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==1 & remunerac<=2 &
contrato==2 & gedad!=2,dpcomma f(4) append clab(25_masSalida)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==2 & remunerac<=2 &
contrato==1 & gedad==2,dpcomma f(4) replace clab(18_24Entrada)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==2 & remunerac<=2 &
contrato==1 & gedad!=2,dpcomma f(4) append clab(25_masEntrada)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==1 & remunerac<=2 &
contrato==1 & gedad==2,dpcomma f(4) append clab(18_24Salida)
qui tabout v_numperiod [iw=x] using "$base\[Link]" if perm==1 & remunerac<=2 &
contrato==1 & gedad!=2,dpcomma f(4) append clab(25_masSalida)