Hello Fellow Statalist,
I have a dataset that contains the following vatiables: Date, CIF, FOB, Country and Descriptions (store as string) in excel. I have imported the data into Stata and converted the string vatiable(Description) to numeric using the encode command:
encode Description, gen(Des)
The encode command generates a numeric variable called Des. However, Des(new variable) is a categorical variable so I went on to create a Dummy variable (with multiple indicators) DumDes to allow me sum or total across columns excluding certain indicators in DumDes(another New variable).
gen DumDes=Des
The indicators for DumDes are Exclusion1, Exclusion2, CommonRegime, SpecialRegime1, SpecialRegime2 and they are coded 1, 2, 3, 4, and 5, respectively.
Now with the above Dummy variable (with multiple indicators) I want to fine the total or sum across Column say for CIF. But when computing the sum of CIF I need not to include both Exclusion1 and Exclusion2. In this case how do I obtain the CIF that excludes the two indicators under DumDes?
When I type the codes:
total CIF I get the sum of CIF
total CIF if DumDes==1 I get the sum of CIF less Exclusion1
total CIF if DumDes==2 I get the sum of CIF less Exclusion2
total CIF if DumDes==1&2 It doesn't give me the value I get when I manually add the two Exclusions(1&2) above
total CIF if DumDes !=1&2 Does not give me the actual CIF value.
NB: CIF = Total CIF - indicators Exclusion 1 and Exclusion2.
In short kindly help me with the Stata command for summing across column using the if option.
Many thanks!
Related Posts with How to Sum or add Across Column with if command
Sequence Index PlotDear Stata Users I am trying to show how individuals move between a set of conditions or states ove…
GMM estimationHi, I'm new in dynamics panel models and I need your help to organise my knowledge. I have 338 obse…
extract year, month, and day from a string variableHi, I have a string variable with the date in the following format Code: * Example generated by -d…
Average time between artists' album releases in panel dataDear Statalist. I have a panel data set containing artists, album releases by artists, and the year …
problem with Ivreg2 resultDear All, After running my regression with ivreg2, in last portion of the result I saw error massage…
Subscribe to:
Post Comments (Atom)
0 Response to How to Sum or add Across Column with if command
Post a Comment