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
egen, groupDear All, Suppose that I have this data set (the original question is here), Code: * Example genera…
Collapse and generate average valuesDear, I want to collapse the years into periods of, say, two years each. For example, if I have a p…
Finding Market SharesHi all, I have a data in the following format. I need to calculate the market share where market sh…
Robust Standard Errors how to get value for Wald Chi^2?Hello everyone! I am running panel data regressions and am using the 'robust' command as I think my…
How to create an aggregate observational unit by adding values by country and year.Hello, I have the following dataset for a number of countries. I would like to generate an aggregate…
Subscribe to:
Post Comments (Atom)
0 Response to How to Sum or add Across Column with if command
Post a Comment