Assignment On Index Numbers Line

Problems In The Construction Of Index Numbers

Before constructing index numbers a careful thought must be given the following problems:

1.    The purpose of the index.

At the very outset the purpose of constructing the index must be very clearly, decided – what the index is to measures and why? There is no all-purpose index. Every index is of limited and particular use. Thus, a price index that is intended to measure consumers’ prices must not include wholesale prices. And if such an index in intended to measure the cost of living of poor families, great care should be taken not to include goods ordinarily used by middle class and upper-income groups.

2.    Selection of a base period.

Whenever index numbers are constructed a reference is made to some base period. The base period of an index number (also called the reference period) is the period against which comparisons are made.

(i)    The base period should be normal one.

The period that is selected as base should be normal, i.e., it should be free from abnormalities like wars, earthquakes, famines, booms, depressions, etc. However, at times it is really difficult to select year which is normal in al respects – a year which is normal in one respect may be abnormal in another.

(ii)    The base period should not be too distant in the past.

It is desirable to have an index based on a fairly recent period, since comparison with a familiar set of circumstances is more helpful than comparison with vaguely remembered conditions.

(iii)    Fixed base or chain base.

While selecting the base a decision has to be made as to whether the base shall remain fixed or not, i.e., whether we have a fixed base or chain base index.

3.    Selection of number of items.

The items included in an index should be determined by the purpose for which the index is constructed. Every item cannot be included while constructing an index number and hence once has to select a sample. It is also necessary to decide the grade or quality of the items to be included in the index. Index numbers shall give wrong result if at one time one set of qualities is included and at another time another set.

4.    Price quotations.

After the commodities have been selected, the next problem is to obtain price quotations for these commodities. It is a will known fact that prices of many commodities vary from place to place and even from shop to shop in the same market. It is impracticable to obtain price quotations from all the places where a commodity is dealt in. A selection must be made of representative places and persons. These places should be those which are well known for trading for that particular commodity.

5.    Choice of an Average.

Theoretically speaking, geometric mean is the best average in the construction of index numbers because of following reasons: (i) in the constructions of index number we are concerned with ratios of relative changes and the geometric mean gives equal weights to equal ratio of change; (ii) geometric mean is less susceptible to major variations as a result of violent fluctuations in the values of the individual items; and (iii) index numbers calculated by using the average are reversible and, therefore, base shifting is easily possible. The geometric mean index always satisfies the time reversal test.

6.    Selection of appropriate weights.

The problem of selecting suitable weights in quite important and at the same quite difficult to decide. The term ‘weight’ refers to the relative importance and hence it is necessary to devise some suitable method whereby the varying importance of the different items by taken into account. This is done by allocating weights. Thus, in the former case, no specific weights are assigned whereas in the latter case specific weights are assigned to various items. It may be pointed out here that no index is unweighted in strict sense of the term as weights implicitly enter the unweighted indices because we are giving equal importance to all the items and hence weights are unity. It is, therefore, necessary to adopt some importance to all the items and hence weights are unity. It is, therefore, necessary to adopt some suitable method of weighting so that arbitrary and haphazard weights may not affect the results. There are two methods of assigning weights: (i) implicit, and (ii) explicit.

7.    Selection of an appropriate formula.

A large number of formulae have been devised for constructing the index. The problem very often is that of selecting the most appropriate formula. The choice of the formula would depend not only on the purpose of the index but also on the data available.

For more help in Problems In The Construction Of Index Numbers click the button below to submit your homework assignment

Lists, , and files

When we read and parse files, there are many opportunities to encounter input that can crash our program so it is a good idea to revisit the guardian pattern when it comes writing programs that read through a file and look for a "needle in the haystack".

Let's revisit our program that is looking for the day of the week on the from lines of our file: From [email protected] Sat Jan 5 09:14:16 2008 Since we are breaking this line into words, we could dispense with the use of and simply look at the first word of the line to determine if we are interested in the line at all. We can use to skip lines that don't have "From" as the first word as follows: fhand = open('mbox-short.txt') for line in fhand: words = line.split() if words[0] != 'From' : continue print words[2] This looks much simpler and we don't even need to do the to remove the newline at the end of the file. But is it better? python Sat Traceback (most recent call last): File "", line 5, in <module> if words[0] != 'From' : continue IndexError: list index out of range It kind of works and we see the day from the first line (Sat) but then the program fails with a traceback error. What went wrong? What messed-up data caused our elegant, clever and very Pythonic program to fail?

You could stare at it for a long time and puzzle through it or ask someone for help, but the quicker and smarter approach is to add a statement. The best place to add the print statement is right before the line where the program failed and print out the data that seems to be causing the failure.

Now this approach may generate a lot of lines of output but at least you will immediately have some clue as to the problem at hand. So we add a print of the variable right before line five. We even add a prefix "Debug:" to the line so we can keep our regular output separate from our debug output. for line in fhand: words = line.split() print 'Debug:', words if words[0] != 'From' : continue print words[2] When we run the program, a lot of output scrolls off the screen but at the end, we see our debug output and the traceback so we know what happened just before the traceback. Debug: ['X-DSPAM-Confidence:', '0.8475'] Debug: ['X-DSPAM-Probability:', '0.0000'] Debug: [] Traceback (most recent call last): File "", line 6, in <module> if words[0] != 'From' : continue IndexError: list index out of range Each debug line is printing the list of words which we get when we the line into words. When the program fails the list of words is empty . If we open the file in a text editor and look at the file, at that point it looks as follows: X-DSPAM-Result: Innocent X-DSPAM-Processed: Sat Jan 5 09:14:16 2008 X-DSPAM-Confidence: 0.8475 X-DSPAM-Probability: 0.0000 Details: The error occurs when our program encounters a blank line! Of course there are "zero words" on a blank line. Why didn't we think of that when we were writing the code. When the code looks for the first word () to check to see if it matches "From", we get an "index out of range" error.

This of course is the perfect place to add some guardian code to avoid checking the first word if the first word is not there. There are many ways to protect this code, we will choose to check the number of words we have before we look at the first word: fhand = open('mbox-short.txt') count = 0 for line in fhand: words = line.split() # print 'Debug:', words if len(words) == 0 : continue if words[0] != 'From' : continue print words[2] First we commented out the debug print statement instead of removing it in case our modification fails and we need to debug again. Then we added a guardian statement that checks to see if we have zero words, and if so, we use to skip to the next line in the file.

We can think of the two statements as helping us refine the set of lines which are "interesting" to us and which we want to process some more. A line which has no words is "uninteresting" to us so we skip to the next line. A line which does not have "From" as its first word is uninteresting to us so we skip it.

The program as modified runs successfully so perhaps it is correct. Our guardian statement does make sure that the will never fail, but perhaps it is not enough. When we are programming, we must always be thinking, "What might go wrong?".

Exercise 2   Figure out which line of the above program is still not properly guarded. See if you can construct a text file which causes the program to fail and then modify the program so that the line is properly guarded and test it to make sure it handles your new text file.

Exercise 3   Rewrite the guardian code in the above example without two statements. Instead use a compound logical expression using the logical operator with a single statement.


Leave a Reply

Your email address will not be published. Required fields are marked *