#### CUSTO TRIBUTARIO ATIVIDADE IMOBILIARIA
#### CUSTO TRIBUTARIO ATIVIDADE IMOBILIARIA
# Atividade : Analise do custo tributarios
# CONFIGURACOES
library(pander) # translate output to HTML / latex
library(magrittr) # use the pipe operator %>%
library(knitr) # kable function formats tables
library(stargazer) # format regression output
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(ggplot2) # graphing functions
library(scales) # escalas dos ggplot
library(xtable) # transforma tabela Excel para Latex
library(MASS) # visualiza decimal em fracoes
library(plyr) # data transformation
library(dplyr) # data transformation
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following object is masked from 'package:MASS':
##
## select
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(broom) # The broom package takes the messy output of built-in functions in R, such as lm, nls, or t.test, and turns them into tidy tibbles.
library(performance) # Analisa regressão
##
## Attaching package: 'performance'
## The following object is masked from 'package:xtable':
##
## display
library(see) # Provides plotting utilities supporting easystats-packages and some extra themes, geoms, and scales for 'ggplot2
library(plotly) # Graficos em 3D para dados com duas variaveis X
##
## Attaching package: 'plotly'
## The following objects are masked from 'package:plyr':
##
## arrange, mutate, rename, summarise
## The following object is masked from 'package:MASS':
##
## select
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(zoo) # S3 Infrastructure for Regular and Irregular Time Series (Z's Ordered Observations)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(dynlm) # Dynamic linear models and time series regression
library(lmtest) # lmtest: Testing Linear Regression Models
library(mosaic) # padronização de variaveis
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
##
## mean
## The following object is masked from 'package:plotly':
##
## do
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following object is masked from 'package:plyr':
##
## count
## The following object is masked from 'package:scales':
##
## rescale
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
## quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
library(strucchange) # analisar quebras estruturais (Chow Test)
## Loading required package: sandwich
library(mctest) # teste para multicolinearidade
library(ivreg) # faz MQO2E
library(modelsummary) # faz um grafico de intervalo bom
##
## Attaching package: 'modelsummary'
## The following object is masked from 'package:mosaic':
##
## msummary
options(scipen = 9)
options(digits = 10, OutDec = ".")
#### PARAMETROS ####
receita.locacao <- 8000*12
## PARAMETROS DA RFB #####
# Parametros das Pessoas Juridicas ####
margem.presumida.irpj.locacao <- 0.32
margem.presumida.csll.locacao <- 0.32
aliq.base.irpj <- 0.15
aliq.add.irpj <- 0.10
aliqCSLL <- 0.09
aliqPIS <- 0.03
aliqCOFINS <- 0.0065
limite.mensal.irpj.base <- 20000
# Parametros das Pessoas Fisicas ####
# Faixas de rendimentos (anual) (limites da faixa)
faixa1.lim.inf <- 0
faixa1.lim.sup <- 1903.98*12
faixa2.lim.inf <- faixa1.lim.sup+0.01
faixa2.lim.sup <- (2826.65*12)
faixa3.lim.inf <- faixa2.lim.sup+0.01
faixa3.lim.sup <- (3751.05*12)
faixa4.lim.inf <- faixa3.lim.sup+0.01
faixa4.lim.sup <- (4664.68*12)
faixa5.lim.inf <- faixa4.lim.sup+0.01
# Faixas de rendimentos (anual) (base de calculo liq. da faixa)
faixa1 <- faixa1.lim.sup
faixa2 <- faixa2.lim.sup - faixa1.lim.sup
faixa3 <- faixa3.lim.sup - faixa2.lim.sup
faixa4 <- faixa4.lim.sup - faixa3.lim.sup
faixa5 <-
# Aliquotas de rendimentos (anual)
aliquota1 <- 0
aliquota2 <- 0.075
aliquota3 <- 0.15
aliquota4 <- 0.225
aliquota5 <- 0.275
# Deduções de locação por faixa #
deducao.faixa1 <- 0
deducao.faixa2 <- 142.8
deducao.faixa3 <- 354.8
deducao.faixa4 <- 636.13
deducao.faixa5 <- 869.36
#### OBTENDO A FUNCAO DO CUSTO TRIBUTARIO DA PESSOA JURIDICA ####
# Definindo a função para cálculo do custo tributário pessoa juridica
custo_tributario_pj_locacao <- function(receita.locacao)
{
# Cálculo do lucro presumido para IRPJ
lucro_presumido_irpj_locacao <- receita.locacao * margem.presumida.irpj.locacao
# Cálculo do lucro presumido para CSLL
lucro_presumido_csll_locacao <- receita.locacao * margem.presumida.csll.locacao
# Cálculo do IRPJ
irpj_valor_base_locacao <- lucro_presumido_irpj_locacao * aliq.base.irpj
# Verificação do adicional de IRPJ
limite_irpj <- limite.mensal.irpj.base * 12
lucro_excedente <- lucro_presumido_irpj_locacao - limite_irpj
if (lucro_excedente > 0) {
adicional_irpj_valor <- lucro_excedente * aliq.add.irpj
irpj_valor_base_locacao <- irpj_valor_base_locacao + adicional_irpj_valor
}
# Cálculo da CSLL
csll_valor_locacao <- lucro_presumido_csll_locacao * aliqCSLL
# Cálculo do PIS
pis_valor_locacao <- receita.locacao * aliqPIS
# Cálculo da COFINS
cofins_valor_locacao <- receita.locacao * aliqCOFINS
# Cálculo do custo tributário total
custo_total_pj_locacao <- irpj_valor_base_locacao + csll_valor_locacao + pis_valor_locacao + cofins_valor_locacao
# Cálculo da alÃquota efetiva
aliquota_efetiva_pj_locacao <- custo_total_pj_locacao / receita.locacao
# Retorno do resultado
return(list(custo_total_pj_locacao = custo_total_pj_locacao, aliquota_efetiva_pj_locacao = aliquota_efetiva_pj_locacao))
}
# Exemplo de uso da função
resultado_locacao_pj <- custo_tributario_pj_locacao(receita.locacao)
cat("O custo tributário para uma empresa com receita de R$", format(receita.locacao, big.mark = ","),
"é de R$", format(resultado_locacao_pj$custo_total_pj_locacao, big.mark=","), "\n")
## O custo tributário para uma empresa com receita de R$ 96,000 é de R$ 10,876.8
cat("A alÃquota efetiva é de", resultado_locacao_pj$aliquota_efetiva_pj_locacao * 100, "%")
## A alÃquota efetiva é de 11.33 %
#### OBTENDO A FUNCAO DO CUSTO TRIBUTARIO DA PESSOA FISICA ####
custo_tributario_pf_locacao <- function(receita.locacao)
{
# Calculo do imposto devido, considerando as faixas de receita e as alÃquotas
if (receita.locacao <= faixa1.lim.sup)
{imposto_devido_pf <- 0}
else if (receita.locacao <= faixa2.lim.sup)
{imposto_devido_pf <-
( (receita.locacao - faixa1.lim.sup) * aliquota2) - deducao.faixa2
}
else if (receita.locacao <= faixa3.lim.sup)
{imposto_devido_pf <-
( ( (faixa2) * aliquota2) - deducao.faixa2 ) +
( ( (receita.locacao - faixa2.lim.sup) * aliquota3) - deducao.faixa3)
}
else if (receita.locacao <= faixa4.lim.sup)
{imposto_devido_pf <-
( ( (faixa2) * aliquota2) - deducao.faixa2 ) +
( ( (faixa3) * aliquota3) - deducao.faixa3 ) +
( ( (receita.locacao - faixa3.lim.sup) * aliquota4) - deducao.faixa4)
}
else
{imposto_devido_pf <-
( ( (faixa2) * aliquota2 ) - deducao.faixa2 ) +
( ( (faixa3) * aliquota3 ) - deducao.faixa3 ) +
( ( (faixa4) * aliquota4 ) - deducao.faixa4 ) +
( ( (receita.locacao - faixa4.lim.sup) * aliquota5) - deducao.faixa5)
}
# Cálculo do custo tributário total PF
custo_total_pf_locacao <- imposto_devido_pf
# Cálculo da alÃquota efetiva PF
aliquota_efetiva_pf_locacao <- custo_total_pf_locacao / receita.locacao
# Retorno do resultado
return(list(custo_total_pf_locacao = custo_total_pf_locacao, aliquota_efetiva_pf_locacao = aliquota_efetiva_pf_locacao))
}
# Exemplo de uso da função
resultado_locacao_pf <- custo_tributario_pf_locacao(receita.locacao)
cat(
"O custo tributário para a pessoa fÃsica com receita de R$",
format(receita.locacao, big.mark = ","),
"é de R$",
format(resultado_locacao_pf$custo_total_pf_locacao, big.mark=","),
", dando uma alÃquota efetiva de", resultado_locacao_pf$aliquota_efetiva_pf_locacao * 100, "%", "\n")
## O custo tributário para a pessoa fÃsica com receita de R$ 96,000 é de R$ 13,964.59 , dando uma alÃquota efetiva de 14.54644792 %
### ANALISANDO AS FUNCOES ATRAVES DE UM GRAFICO ####
# Define a função base para gerar o gráfico
plot_custo_tributario_locacao_pj_pf <- function(receita.locacao)
{
# Define o intervalo de receita
receita.locacao_intervalo <- seq(1, 90000, 10000)
# Calcula o custo tributário PJ para cada valor de receita
custo_tributario_pj_locacao <- sapply(receita.locacao_intervalo, function(receita.locacao) {
custo_tributario_pj_locacao(receita.locacao)$custo_total_pj_locacao
})
# Calcula o custo tributário PF para cada valor de receita
custo_tributario_pf_locacao <- sapply(receita.locacao_intervalo, function(receita.locacao) {
custo_tributario_pf_locacao(receita.locacao)$custo_total_pf_locacao
})
# Cria um data frame com os valores de receita e de custo tributário
df <- data.frame(receita.locacao = receita.locacao_intervalo, custo_tributario_pj_locacao = custo_tributario_pj_locacao, custo_tributario_pf_locacao = custo_tributario_pf_locacao)
# Cria o gráfico
ggplot(df, aes(x = receita.locacao)) +
geom_smooth(aes(y = custo_tributario_pj_locacao, color = "Pessoa JurÃdica"), se = FALSE, size = 1) +
geom_smooth(aes(y = custo_tributario_pf_locacao, color = "Pessoa FÃsica"), se = FALSE, size = 1) +
scale_color_manual(values = c("Pessoa JurÃdica" = "#440154FF", "Pessoa FÃsica" = "#21908CFF")) +
scale_y_continuous(labels = comma_format(), expand = expansion(mult = c(0.05, 0.1))) +
scale_x_continuous(labels = comma_format(), expand = expansion(mult = c(0.05, 0.1))) +
labs(title = "Locação: custo tributário em função da receita de aluguéis",
subtitle = "Analisando lucro presumido",
x = "Receita anual de aluguéis (R$)",
y = "Custo tributário (R$)",
color = "Perfil tributário") +
theme(plot.title = element_text(family= "Segoe UI", size = 16, face = "bold"),
axis.title = element_text(family= "Segoe UI",size = 14),
axis.text = element_text(family= "Segoe UI",size = 12),
legend.title = element_text(family= "Segoe UI",size = 12, face = "bold"))
}
plot_custo_tributario_locacao_pj_pf(receita.locacao)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
