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
cmp multivariate probitHi, I am running a multivariate probit model using the cmp function on 4 binary dependent variables…
Year and Month fixed effectsHi, I would like to run a regression with year month fixed effects. My data consists of year and mo…
Boxplot in complex design surveyDear Statalist users: I have a data set with weight syntax as below, How can I run a box plot with …
Reshape long to wideHi everyone, Im a newbie in stata and will really appreciate if somebody will help me. I have searc…
Panel GARCH Model?Dear all, I am attempting to estimate a panel EGARCH-M model in STATA, as of yet I have had no luck…
Subscribe to:
Post Comments (Atom)
0 Response to How to Sum or add Across Column with if command
Post a Comment