Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • infix and infile commands not recognizing dictionary

    I am trying to import fixed format datasets. For each month, I have a dataset and the corresponding dictionary. The dictionary might change from month to month.

    I managed to import the dataset manually specifying the dictionary in the command. However, when I try to automate the code calling for the dictionary it does not work.

    Code:
    . cd "C:\Users\Paula\Dropbox\Pesquisa\DADOS\DATASUS\auxiliares\SIA_SIH_SIGTAP\SIGTAP_2008+\TabelaUnificada_200801"
    C:\Users\Paula\Dropbox\Pesquisa\DADOS\DATASUS\auxiliares\SIA_SIH_SIGTAP\SIGTAP_2008+\TabelaUnificada_200801
    
    . 
    . infix str cod_proc 1-10 str nom_proc 11-260 str complex 261-261 str sex 262-262 ///
    > str max_exe 263-266 str qt_dias 267-270 str qt_pts 271-274 str idade_max 275-278 ///
    > str idade_min 279-282 str vl_sh 283-292 str vl_sa 293-302 str vl_sp 303-312 ///
    > str financ 313-314 str rubr 315-320 str anomes 321-326 using ///
    > "tb_procedimento.txt", clear
    (4,190 observations read)
    
    . 
    . infix using "tb_procedimento_layout.txt", using ("tb_procedimento.txt") clear
    Coluna,Tamanho,Inicio,Fim,Tipo
    file does not contain dictionary
    r(613);
    
    end of do-file
    
    r(613);
    
    .
    Same happens when I try using the command infile.
    Code:
    . infile using "tb_procedimento_layout.txt", using ("tb_procedimento.txt") clear
    
    Coluna,Tamanho,Inicio,Fim,Tipo
    file does not contain dictionary
    r(613);
    
    end of do-file
    
    r(613);
    
    .
    My dictionary looks like this. It still does not work when I delete the first row
    Code:
    Coluna,Tamanho,Inicio,Fim,Tipo
    CO_PROCEDIMENTO,10,1,10,VARCHAR2
    NO_PROCEDIMENTO,250,11,260,VARCHAR2
    TP_COMPLEXIDADE,1,261,261,VARCHAR2
    TP_SEXO,1,262,262,VARCHAR2
    QT_MAXIMA_EXECUCAO,4,263,266,NUMBER
    QT_DIAS_PERMANENCIA,4,267,270,NUMBER
    QT_PONTOS,4,271,274,NUMBER
    VL_IDADE_MINIMA,4,275,278,NUMBER
    VL_IDADE_MAXIMA,4,279,282,NUMBER
    VL_SH,10,283,292,NUMBER
    VL_SA,10,293,302,NUMBER
    VL_SP,10,303,312,NUMBER
    CO_FINANCIAMENTO,2,313,314,VARCHAR2
    CO_RUBRICA,6,315,320,VARCHAR2
    DT_COMPETENCIA,6,321,326,DATE

  • #2
    A dictionary has .dct extension.

    Please see this thread: https://www.statalist.org/forums/for...onary-question
    Best regards,

    Marcos

    Comment


    • #3
      Marcos, I understand that a dictionary can also have a txt extension in which case it would need to be specified. Dct is the default option (this, if no extension is specified, .dct is assumed).

      The post you sent creates the dictionary in a manual way (which I managed to do above). My question, however, concerns how to make Stata read the dictionary file correctly. In other words, how should my dictionary file be formatted in a way that Stata can read it.

      My dictionary file is currently formatted as below
      Code:
      Coluna,Tamanho,Inicio,Fim,Tipo
      CO_PROCEDIMENTO,10,1,10,VARCHAR2
      NO_PROCEDIMENTO,250,11,260,VARCHAR2
      TP_COMPLEXIDADE,1,261,261,VARCHAR2
      TP_SEXO,1,262,262,VARCHAR2
      QT_MAXIMA_EXECUCAO,4,263,266,NUMBER
      QT_DIAS_PERMANENCIA,4,267,270,NUMBER
      QT_PONTOS,4,271,274,NUMBER
      VL_IDADE_MINIMA,4,275,278,NUMBER
      VL_IDADE_MAXIMA,4,279,282,NUMBER
      VL_SH,10,283,292,NUMBER
      VL_SA,10,293,302,NUMBER
      VL_SP,10,303,312,NUMBER
      CO_FINANCIAMENTO,2,313,314,VARCHAR2
      CO_RUBRICA,6,315,320,VARCHAR2
      DT_COMPETENCIA,6,321,326,DATE

      Comment


      • #4
        As Stata is telling you, that is not a dictionary in Stata's sense. It is just a data file. A dictionary always starts with metadata and indeed the keyword dictionary. There are examples in the help for infile

        You are showing one file, presumably one of
        tb_procedimento_layout.txt
        tb_procedimento.txt Which file are you showing us? Please show us the other file.

        Comment


        • #5
          Thanks Nick Cox. I went over the examples in the help for
          HTML Code:
          infile
          but still have not managed to get around.

          Responding to your question: I have two files, one containing the data (tb_procedimento.txt) and another one containing the dictionary (b_procedimento_layout.txt).

          Below a sample of the tb_procedimento.txt file:
          Code:
          0101010010ATIVIDADE EDUCATIVA / ORIENTACAO EM GRUPO NA ATENCAO BASICA                                                                                                                                                                                               1I9999999900000048133100000000000000000000000000000001      200801
          0101010028ATIVIDADE EDUCATIVA / ORIENTACAO EM GRUPO NA ATENCAO ESPECIALIZADA                                                                                                                                                                                        2I9999999900000084133100000000000000000270000000000006      200801
          0101010036PRATICA CORPORAL / ATIVIDADE FISICA EM GRUPO                                                                                                                                                                                                              1I9999999900000072133100000000000000000000000000000001      200801
          0101010044PRATICAS CORPORAIS EM MEDICINA TRADICIONAL CHINESA                                                                                                                                                                                                        1I9999999900000072133100000000000000000000000000000001      200801
          0101020015ACAO COLETIVA DE APLICACAO TOPICA DE FLUOR GEL                                                                                                                                                                                                            1I9999999900000048133100000000000000000000000000000001      200801
          0101020023ACAO COLETIVA DE BOCHECHO FLUORADO                                                                                                                                                                                                                        1I9999999900000048133100000000000000000000000000000001      200801
          0101020031ACAO COLETIVA DE ESCOVACAO DENTAL SUPERVISIONADA                                                                                                                                                                                                          1I9999999900000036133100000000000000000000000000000001      200801
          0101020040ACAO COLETIVA DE EXAME BUCAL C/ FINALIDADE EPIDEMIOLOGICA                                                                                                                                                                                                 1I9999999900000000133100000000000000000000000000000001      200801
          0101020058APLICACAO DE CARIOSTATICO (POR DENTE)                                                                                                                                                                                                                     1I9999999900000000133100000000000000000000000000000001      200801
          0101020066APLICACAO DE SELANTE (POR DENTE)                                                                                                                                                                                                                          1I9999999900000000133100000000000000000000000000000001      200801
          0101020074APLICACAO TOPICA DE FLUOR (INDIVIDUAL POR SESSAO)                                                                                                                                                                                                         1I9999999900000000133100000000000000000000000000000001      200801
          0101020082EVIDENCIACAO DE PLACA BACTERIANA                                                                                                                                                                                                                          1I9999999900000000133100000000000000000000000000000001      200801
          0101020090SELAMENTO PROVISORIO DE CAVIDADE DENTARIA                                                                                                                                                                                                                 1I9999999900000000133100000000000000000000000000000001      200801
          0101030010VISITA DOMICILIAR POR PROFISSIONAL DE NIVEL MEDIO                                                                                                                                                                                                         1I9999999900000000133100000000000000000000000000000001      200801
          0101030029VISITA DOMICILIAR/INSTITUCIONAL EM REABILTACAO -POR PROFISSIONAL DE NIVEL SUPERIOR                                                                                                                                                                        1I9999999900000000133100000000000000000000000000000001      200801
          0101040016APLICACAO DE SUPLEMENTOS DE MICRONUTRIENTES                                                                                                                                                                                                               1I9999999900000000059900000000000000000000000000000001      200801
          0101040024AVALIACAO ANTROPOMETRICA                                                                                                                                                                                                                                  1I9999999900000000007100000000000000000000000000000001      200801
          0101040032COLETA EXTERNA DE LEITE MATERNO (POR DOADORA)                                                                                                                                                                                                             2F9999999900000144059900000000000000000063000000000006      200801
          0101040040PASTEURIZACAO DO LEITE HUMANO (CADA 5 LITROS)                                                                                                                                                                                                             2N9999999900009999999900000000000000000050000000000006      200801
          0102010013APLICACAO DE  MULTA                                                                                                                                                                                                                                       0N9999999900009999999900000000000000000000000000000007      200801
          0102010021APLICACAO DE ADVERTENCIA                                                                                                                                                                                                                                  0N9999999900009999999900000000000000000000000000000007      200801
          0102010030APLICACAO DE INTERDICAO DE PRODUTO                                                                                                                                                                                                                        0N9999999900009999999900000000000000000000000000000007      200801
          0102010048APLICACAO DE INTERDICAO PARCIAL / TOTAL DE ESTABELECIMENTO                                                                                                                                                                                                0N9999999900009999999900000000000000000000000000000007      200801
          0102010056ATIVIDADES EDUCATIVAS P/ PROFISSIONAIS DO SETOR REGULADO                                                                                                                                                                                                  0N9999999900009999999900000000000000000000000000000007      200801
          0102010064AVALIACAO DE PROJETO BASICO DE ARQUITETURA                                                                                                                                                                                                                0N9999999900009999999900000000000000000000000000000007      200801
          0102010072CADASTRO DE ESTABELECIMENTOS SUJEITOS A VIGILANCIA SANITARIA                                                                                                                                                                                              0N9999999900009999999900000000000000000000000000000007      200801
          And the dictionary necessary to read the data (file tb_procedimento_layout.txt). It says that, for instance, the first variable (CO_PROCEDIMENTO) occupies 10 positions in the dataset (it goes from position 1 to position 10). Could I somehow automate a code that would make this dictionary readable in Stata? I have plenty of data files which comes along with dictionary files in the format below.
          Code:
          Coluna,Tamanho,Inicio,Fim,Tipo
          CO_PROCEDIMENTO,10,1,10,VARCHAR2
          NO_PROCEDIMENTO,250,11,260,VARCHAR2
          TP_COMPLEXIDADE,1,261,261,VARCHAR2
          TP_SEXO,1,262,262,VARCHAR2
          QT_MAXIMA_EXECUCAO,4,263,266,NUMBER
          QT_DIAS_PERMANENCIA,4,267,270,NUMBER
          QT_PONTOS,4,271,274,NUMBER
          VL_IDADE_MINIMA,4,275,278,NUMBER
          VL_IDADE_MAXIMA,4,279,282,NUMBER
          VL_SH,10,283,292,NUMBER
          VL_SA,10,293,302,NUMBER
          VL_SP,10,303,312,NUMBER
          CO_FINANCIAMENTO,2,313,314,VARCHAR2
          CO_RUBRICA,6,315,320,VARCHAR2
          DT_COMPETENCIA,6,321,326,DATE

          Comment


          • #6
            Again, neither file is a dictionary file in Stata's sense. Whether it's a dictionary file in some other software is immaterial to infile or infix. VARCHAR2 isn't Stata jargon. But you seem to have written the infix command to read this file, so I don't know what you're missing.

            The date variable needs some engineering. You have read in string values such as "200801". The conversion there could be

            Code:
            gen mdate = ym(real(substr(anomes, 1, 4)), real(substr(anomes, 5, 2)))
            format mdate %tm
            I imagine you need to destring much of the rest and define value labels too, but the "dictionary" is no help there.

            Comment

            Working...
            X