I am going to generate a variable that shows how many export varieties firms export.
Firm ID: NPC_FIC
Commodity Code: artigo
Type of trade (Export =2, Import=1): fluxo
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double NPC_FIC str10 fluxo str24 artigo 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 10006 "Exporta��o" "01012990" 500000001 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000002 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000033 "" "" 500000050 "" "" 500000050 "" "" 500000050 "" "" 500000050 "" "" 500000050 "" "" 500000050 "" "" 500000069 "" "" 500000069 "" "" 500000073 "" "" 500000073 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000083 "" "" 500000101 "" "" 500000101 "" "" 500000101 "" "" 500000101 "" "" 500000101 "" "" 500000101 "" "" 500000104 "" "" 500000106 "" "" 500000113 "" "" 500000113 "" "" 500000113 "" "" 500000113 "" "" 500000119 "Exporta��o" "07019090" 500000119 "Exporta��o" "07019090" 500000119 "Exporta��o" "07019090" 500000119 "Exporta��o" "07019090" 500000119 "Importa��o" "07019090" 500000119 "Importa��o" "07019090" 500000119 "Importa��o" "07019090" 500000119 "Importa��o" "07019090" 500000119 "Importa��o" "07019090"
Code:
by NPC_FIC fluxo (artigo), sort: gen n_ex = sum(artigo != artigo[_n-1]) by NPC_FIC fluxo (artigo): replace n_ex = n_ex[_N]
Cheers,
Paris
0 Response to Generating a variable based on other variable
Post a Comment