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
GMM Standard Errors and SAR ModelsAll: Please excuse this question as I am an ex-GeoDa user coming to STATA. In the Spatial Autoregre…
Reorganising panel dataI have Panel data ranging over 8 time periods (quarters). For each individual, there are 4 quarters…
Granger causality test for Panel data regressionI want to test the direction of causality for my panel data. In order to do so, I wanted to carry ou…
Plotting by subgroupsHi, I am Soma Gecse, an Economics student from Warwick University. With my group, we are investiga…
panel data analysisHi, I am getting negative test statistic for hausman test to check b/w random and fixed effects mode…
Subscribe to:
Post Comments (Atom)
0 Response to How to Sum or add Across Column with if command
Post a Comment